@digigov/cli-build 2.0.0-07ee8440 → 2.0.0-0b806366
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.prettierrc.cjs +1 -0
- package/.rush/temp/shrinkwrap-deps.json +427 -32
- package/common.js +3 -3
- package/copy-files.js +26 -79
- package/eslint.config.js +3 -0
- package/generate-registry.js +96 -149
- package/index.js +151 -81
- package/package.json +14 -27
- package/transform-imports-plugin.js +263 -0
- package/tsconfig.base.json +21 -59
- package/tsconfig.json +3 -7
- package/babel.common.cjs +0 -119
- package/babel.config.cjs +0 -1
- package/build.js +0 -85
- package/tsconfig.common.json +0 -27
package/index.js
CHANGED
|
@@ -1,36 +1,38 @@
|
|
|
1
|
-
import { DigigovCommand, resolveProject, logger } from
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import {
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
import { DigigovCommand, resolveProject, logger } from '@digigov/cli/lib';
|
|
2
|
+
import { build } from '@rslib/core';
|
|
3
|
+
import copyFiles from './copy-files.js';
|
|
4
|
+
|
|
5
|
+
import { Option } from 'commander';
|
|
6
|
+
import path from 'path';
|
|
7
|
+
import glob from 'globby';
|
|
8
|
+
import assert from 'assert';
|
|
9
|
+
import { getProjectTsconfig } from './common.js';
|
|
10
|
+
import { generateLazyRegistry, generateRegistry } from './generate-registry.js';
|
|
11
|
+
import transformImportsPlugin from './transform-imports-plugin.js';
|
|
12
|
+
|
|
13
|
+
const command = new DigigovCommand('build', import.meta.url)
|
|
13
14
|
.option(
|
|
14
|
-
|
|
15
|
-
|
|
15
|
+
'--generate-registry',
|
|
16
|
+
'Generate a registry file for the build output'
|
|
16
17
|
)
|
|
17
18
|
.addOption(
|
|
18
|
-
new Option(
|
|
19
|
+
new Option('--include-stories', 'Include stories in the output').implies({
|
|
19
20
|
generateRegistry: true,
|
|
20
|
-
})
|
|
21
|
+
})
|
|
21
22
|
)
|
|
22
23
|
.action(main);
|
|
23
24
|
export default command;
|
|
24
25
|
|
|
25
|
-
const SRC_GLOB =
|
|
26
|
+
const SRC_GLOB = 'src/**/*.{tsx,ts,js,jsx}';
|
|
26
27
|
const TEST_GLOBS = [
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
'**/*.test.{js,jsx,ts,tsx}',
|
|
29
|
+
'**/*.spec.{js,jsx,ts,tsx}',
|
|
30
|
+
'**/__tests__/**/*.{js,jsx,ts,tsx}',
|
|
30
31
|
];
|
|
31
32
|
const STORIES_GLOBS = [
|
|
32
|
-
|
|
33
|
-
|
|
33
|
+
'**/*.stories.{js,jsx,ts,tsx}',
|
|
34
|
+
'**/__stories__/**/*.{js,jsx,ts,tsx}',
|
|
35
|
+
'**/__stories__/*.{js,jsx,ts,tsx}',
|
|
34
36
|
];
|
|
35
37
|
|
|
36
38
|
/**
|
|
@@ -40,67 +42,135 @@ const STORIES_GLOBS = [
|
|
|
40
42
|
* @param {DigigovCommand} ctx
|
|
41
43
|
*/
|
|
42
44
|
async function main(options, ctx) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* The project tsconfig, or undefined if the project is not using TypeScript
|
|
49
|
-
* @type {string | undefined}
|
|
50
|
-
*/
|
|
51
|
-
let tsconfig;
|
|
52
|
-
if (project.isTs) {
|
|
53
|
-
tsconfig = getProjectTsconfig(project.root);
|
|
54
|
-
assert(tsconfig, "Expected tsconfig to be in project");
|
|
55
|
-
await generateTypeDeclarationFiles(project, tsconfig, ctx);
|
|
56
|
-
}
|
|
45
|
+
/** @type {string[]} */
|
|
46
|
+
let filesToDelete = [];
|
|
47
|
+
let isCleaningUp = false;
|
|
48
|
+
let signalHandlersRegistered = false;
|
|
57
49
|
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
})
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
50
|
+
const cleanup = async () => {
|
|
51
|
+
if (isCleaningUp) return;
|
|
52
|
+
isCleaningUp = true;
|
|
53
|
+
|
|
54
|
+
if (options.generateRegistry && filesToDelete.length > 0) {
|
|
55
|
+
logger.debug('Deleting temporary registry files...');
|
|
56
|
+
try {
|
|
57
|
+
await ctx.exec('rimraf', filesToDelete, {}, true);
|
|
58
|
+
} catch (error) {
|
|
59
|
+
logger.error('Error during cleanup:', error);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Remove signal handlers after cleanup
|
|
64
|
+
if (signalHandlersRegistered) {
|
|
65
|
+
process.off('SIGINT', handleSignal);
|
|
66
|
+
process.off('SIGTERM', handleSignal);
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
/** @param {string} signal */
|
|
71
|
+
const handleSignal = async (signal) => {
|
|
72
|
+
logger.log(`\nReceived ${signal}, cleaning up...`);
|
|
73
|
+
await cleanup();
|
|
74
|
+
process.exit(signal === 'SIGINT' ? 130 : 143);
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
// Register signal handlers
|
|
78
|
+
process.on('SIGINT', handleSignal);
|
|
79
|
+
process.on('SIGTERM', handleSignal);
|
|
80
|
+
signalHandlersRegistered = true;
|
|
81
|
+
|
|
82
|
+
try {
|
|
83
|
+
const project = resolveProject();
|
|
84
|
+
|
|
85
|
+
await ctx.exec('rimraf', [project.distDir]);
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* The project tsconfig, or undefined if the project is not using TypeScript
|
|
89
|
+
* @type {string | undefined}
|
|
90
|
+
*/
|
|
91
|
+
let tsconfig;
|
|
92
|
+
if (project.isTs) {
|
|
93
|
+
tsconfig = getProjectTsconfig(project.root);
|
|
94
|
+
assert(tsconfig, 'Expected tsconfig to be in project');
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if (options.generateRegistry) {
|
|
98
|
+
logger.debug('Generating registry files...');
|
|
99
|
+
|
|
100
|
+
const initialFiles = await glob(path.join(project.root, SRC_GLOB), {
|
|
101
|
+
ignore: [...TEST_GLOBS, ...STORIES_GLOBS],
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
const filesToIncludeInRegistry = initialFiles.filter(
|
|
105
|
+
(file) => !(file.includes('native') || file.endsWith('.d.ts'))
|
|
106
|
+
);
|
|
107
|
+
let storiesFiles = null;
|
|
108
|
+
if (options.includeStories) {
|
|
109
|
+
logger.debug('Including stories in the registry...');
|
|
110
|
+
|
|
111
|
+
storiesFiles = await glob(
|
|
112
|
+
STORIES_GLOBS.map((glob) =>
|
|
113
|
+
path.join(project.root, project.src, glob)
|
|
114
|
+
),
|
|
115
|
+
{
|
|
116
|
+
ignore: ['**/*.native.*, **/*.d.ts'],
|
|
117
|
+
}
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
filesToDelete = await Promise.all([
|
|
122
|
+
storiesFiles
|
|
123
|
+
? generateRegistry(project, storiesFiles, 'stories-registry.ts')
|
|
124
|
+
: null,
|
|
125
|
+
generateRegistry(project, filesToIncludeInRegistry, 'registry.ts'),
|
|
126
|
+
generateLazyRegistry(project, filesToIncludeInRegistry, 'lazy.ts'),
|
|
127
|
+
]).then((paths) => paths.filter((p) => p !== null));
|
|
128
|
+
|
|
129
|
+
logger.log('Generated registry files');
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const IGNORE_BLOBS = [...TEST_GLOBS, ...STORIES_GLOBS].map(
|
|
133
|
+
(path) => `!${project.root}/${path}`
|
|
93
134
|
);
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
135
|
+
|
|
136
|
+
logger.debug('Building...');
|
|
137
|
+
await build({
|
|
138
|
+
source: {
|
|
139
|
+
tsconfigPath: tsconfig,
|
|
140
|
+
entry: {
|
|
141
|
+
index: [`${project.root}/${SRC_GLOB}`, ...IGNORE_BLOBS],
|
|
142
|
+
},
|
|
143
|
+
},
|
|
144
|
+
output: {
|
|
145
|
+
distPath: {
|
|
146
|
+
root: project.distDir,
|
|
147
|
+
},
|
|
148
|
+
},
|
|
149
|
+
lib: [
|
|
150
|
+
{
|
|
151
|
+
redirect: {
|
|
152
|
+
dts: {
|
|
153
|
+
extension: true,
|
|
154
|
+
},
|
|
155
|
+
},
|
|
156
|
+
bundle: false,
|
|
157
|
+
dts: {
|
|
158
|
+
bundle: false,
|
|
159
|
+
autoExtension: true,
|
|
160
|
+
},
|
|
161
|
+
format: 'esm',
|
|
162
|
+
plugins: [
|
|
163
|
+
transformImportsPlugin(project, ['@uides/react-qr-reader']),
|
|
164
|
+
],
|
|
165
|
+
},
|
|
166
|
+
],
|
|
99
167
|
});
|
|
100
|
-
logger.
|
|
101
|
-
}
|
|
168
|
+
logger.debug('Building done.');
|
|
102
169
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
170
|
+
logger.debug('Copying files to build directory...');
|
|
171
|
+
copyFiles();
|
|
172
|
+
logger.debug('Files copied.');
|
|
173
|
+
} finally {
|
|
174
|
+
await cleanup();
|
|
175
|
+
}
|
|
106
176
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@digigov/cli-build",
|
|
3
|
-
"version": "2.0.0-
|
|
3
|
+
"version": "2.0.0-0b806366",
|
|
4
4
|
"description": "Build plugin for Digigov CLI",
|
|
5
5
|
"main": "./index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -8,43 +8,28 @@
|
|
|
8
8
|
"license": "BSD-2-Clause",
|
|
9
9
|
"private": false,
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"@babel/cli": "7.12.1",
|
|
12
|
-
"@babel/compat-data": "7.12.5",
|
|
13
|
-
"@babel/core": "7.26.0",
|
|
14
|
-
"@babel/helper-validator-identifier": "7.9.5",
|
|
15
|
-
"@babel/plugin-proposal-class-properties": "7.12.1",
|
|
16
|
-
"@babel/plugin-proposal-object-rest-spread": "7.12.1",
|
|
17
|
-
"@babel/plugin-transform-object-assign": "7.12.1",
|
|
18
|
-
"@babel/plugin-transform-runtime": "7.12.1",
|
|
19
|
-
"@babel/preset-env": "7.12.13",
|
|
20
|
-
"@babel/preset-react": "7.12.13",
|
|
21
|
-
"@babel/preset-typescript": "7.12.1",
|
|
22
|
-
"babel-plugin-inline-import-data-uri": "1.0.1",
|
|
23
|
-
"babel-plugin-module-resolver": "4.0.0",
|
|
24
|
-
"babel-plugin-optimize-clsx": "1.1.1",
|
|
25
|
-
"babel-plugin-react-remove-properties": "0.3.0",
|
|
26
|
-
"babel-plugin-transform-dev-warning": "0.1.1",
|
|
27
|
-
"babel-plugin-transform-react-constant-elements": "6.23.0",
|
|
28
|
-
"babel-plugin-transform-react-remove-prop-types": "0.4.24",
|
|
29
11
|
"fs-extra": "11.2.0",
|
|
30
12
|
"globby": "11.0.0",
|
|
31
|
-
"babel-plugin-istanbul": "7.0.0",
|
|
32
13
|
"publint": "0.1.8",
|
|
33
14
|
"rimraf": "3.0.2",
|
|
34
|
-
"esbuild": "0.23.0",
|
|
35
15
|
"commander": "12.1.0",
|
|
36
|
-
"ts-morph": "25.0.0"
|
|
16
|
+
"ts-morph": "25.0.0",
|
|
17
|
+
"@rslib/core": "0.15.1"
|
|
37
18
|
},
|
|
38
19
|
"devDependencies": {
|
|
20
|
+
"@digigov/cli": "2.0.0-0b806366",
|
|
21
|
+
"@digigov/cli-lint": "2.0.0-0b806366",
|
|
39
22
|
"publint": "0.1.8",
|
|
40
23
|
"vitest": "2.1.3",
|
|
41
|
-
"@digigov/cli-test": "2.0.0-
|
|
24
|
+
"@digigov/cli-test": "2.0.0-0b806366",
|
|
42
25
|
"@types/fs-extra": "11.0.4",
|
|
43
|
-
"@types/node": "
|
|
44
|
-
"typescript": "5.6.2"
|
|
26
|
+
"@types/node": "20.17.24",
|
|
27
|
+
"typescript": "5.6.2",
|
|
28
|
+
"eslint": "9.16.0",
|
|
29
|
+
"prettier": "3.4.2"
|
|
45
30
|
},
|
|
46
31
|
"peerDependencies": {
|
|
47
|
-
"@digigov/cli": "2.0.0-
|
|
32
|
+
"@digigov/cli": "2.0.0-0b806366",
|
|
48
33
|
"next": "13.1.1"
|
|
49
34
|
},
|
|
50
35
|
"peerDependenciesMeta": {
|
|
@@ -53,6 +38,8 @@
|
|
|
53
38
|
}
|
|
54
39
|
},
|
|
55
40
|
"scripts": {
|
|
56
|
-
"publint": "publint"
|
|
41
|
+
"publint": "publint",
|
|
42
|
+
"lint": "digigov lint",
|
|
43
|
+
"typecheck": "tsc"
|
|
57
44
|
}
|
|
58
45
|
}
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
import { logger } from '@digigov/cli/lib';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import fs from 'fs';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @param {Record<string, any>} project
|
|
7
|
+
* @param {string[]} [pathsToIgnore=[]]
|
|
8
|
+
* @returns {import('@rslib/core').rsbuild.RsbuildPlugin}
|
|
9
|
+
*/
|
|
10
|
+
export default function transformImportsPlugin(project, pathsToIgnore = []) {
|
|
11
|
+
const projectName = project['name'];
|
|
12
|
+
const projectRoot = project['root'];
|
|
13
|
+
const workspace = project['workspace'];
|
|
14
|
+
|
|
15
|
+
if (Object.keys(workspace).length === 0) {
|
|
16
|
+
throw new Error(
|
|
17
|
+
`transform-imports-plugin can only be used in workspace projects. ${projectName} is not a workspace project.`
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const projectScopes =
|
|
22
|
+
workspace.config.projects.map((p) => p.packageName) ?? [];
|
|
23
|
+
|
|
24
|
+
if (projectScopes.length === 0) {
|
|
25
|
+
logger.warn(
|
|
26
|
+
`No project scopes found for ${projectName}. Plugin may not transform any imports.`
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const importRegex =
|
|
31
|
+
/(?:^|[^'"\\])(?:from|import)\s*\(\s*['"]([^'"]+)['"]\s*\)|(?:from|import)\s+['"]([^'"]+)['"]/gm;
|
|
32
|
+
|
|
33
|
+
const packageJsonCache = new Map();
|
|
34
|
+
const fileExistsCache = new Map();
|
|
35
|
+
const resolvedImportsCache = new Map();
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Check if a package uses exports field
|
|
39
|
+
* @param {string} packageName
|
|
40
|
+
* @returns {boolean}
|
|
41
|
+
*/
|
|
42
|
+
function hasExportsField(packageName) {
|
|
43
|
+
if (packageJsonCache.has(packageName)) {
|
|
44
|
+
return packageJsonCache.get(packageName);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
try {
|
|
48
|
+
const pkgJsonPath = path.join(
|
|
49
|
+
projectRoot,
|
|
50
|
+
'node_modules',
|
|
51
|
+
packageName,
|
|
52
|
+
'package.json'
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
if (fs.existsSync(pkgJsonPath)) {
|
|
56
|
+
const pkgJson = JSON.parse(fs.readFileSync(pkgJsonPath, 'utf8'));
|
|
57
|
+
const hasExports = !!pkgJson.exports;
|
|
58
|
+
packageJsonCache.set(packageName, hasExports);
|
|
59
|
+
return hasExports;
|
|
60
|
+
}
|
|
61
|
+
} catch (error) {
|
|
62
|
+
logger.warn(`Failed to read package.json for ${packageName}:`, error);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
packageJsonCache.set(packageName, false);
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Check if a file exists with any of the given suffixes (with caching)
|
|
71
|
+
* @param {string} basePath
|
|
72
|
+
* @param {string[]} suffixes
|
|
73
|
+
* @returns {string | null} The matching suffix or null
|
|
74
|
+
*/
|
|
75
|
+
function findFileWithSuffix(basePath, suffixes) {
|
|
76
|
+
const cacheKey = `${basePath}:${suffixes.join(',')}`;
|
|
77
|
+
|
|
78
|
+
if (fileExistsCache.has(cacheKey)) {
|
|
79
|
+
return fileExistsCache.get(cacheKey);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
for (const suffix of suffixes) {
|
|
83
|
+
const fullPath = basePath + suffix;
|
|
84
|
+
if (fs.existsSync(fullPath)) {
|
|
85
|
+
fileExistsCache.set(cacheKey, suffix);
|
|
86
|
+
return suffix;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
fileExistsCache.set(cacheKey, null);
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Extract the package name from an import path
|
|
96
|
+
* @param {string} importPath
|
|
97
|
+
* @returns {string} The package name
|
|
98
|
+
*/
|
|
99
|
+
function getPackageName(importPath) {
|
|
100
|
+
if (importPath.startsWith('@')) {
|
|
101
|
+
const parts = importPath.split('/');
|
|
102
|
+
return parts.slice(0, 2).join('/');
|
|
103
|
+
}
|
|
104
|
+
// @ts-expect-error - assured string
|
|
105
|
+
return importPath.split('/')[0];
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Check if a package is internal based on project scopes
|
|
110
|
+
* @param {string} packageName
|
|
111
|
+
* @returns {boolean}
|
|
112
|
+
*/
|
|
113
|
+
function isInternalPackage(packageName) {
|
|
114
|
+
return projectScopes.some((scope) => packageName.startsWith(scope));
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Determine if an import should be skipped
|
|
119
|
+
* @param {string} importPath
|
|
120
|
+
* @returns {boolean}
|
|
121
|
+
*/
|
|
122
|
+
function shouldSkipImport(importPath) {
|
|
123
|
+
return (
|
|
124
|
+
!importPath ||
|
|
125
|
+
importPath.includes(projectName) ||
|
|
126
|
+
pathsToIgnore.some((ignorePath) => importPath.startsWith(ignorePath)) ||
|
|
127
|
+
importPath.endsWith('.js') ||
|
|
128
|
+
importPath.endsWith('.mjs') ||
|
|
129
|
+
importPath.endsWith('.cjs') ||
|
|
130
|
+
importPath.startsWith('.') ||
|
|
131
|
+
importPath.startsWith('/') ||
|
|
132
|
+
importPath.startsWith('node:') ||
|
|
133
|
+
!importPath.includes('/')
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Transform an internal package import
|
|
139
|
+
* @param {string} importPath
|
|
140
|
+
* @returns {string | null}
|
|
141
|
+
*/
|
|
142
|
+
function transformInternalPackageImport(importPath) {
|
|
143
|
+
const parts = importPath.split('/');
|
|
144
|
+
const dependencyName = parts[1];
|
|
145
|
+
|
|
146
|
+
if (!dependencyName) return null;
|
|
147
|
+
|
|
148
|
+
// Replace the dependency name to point to /src
|
|
149
|
+
const srcPath = [...parts];
|
|
150
|
+
srcPath[1] = `${dependencyName}/src`;
|
|
151
|
+
const srcImportPath = srcPath.join('/');
|
|
152
|
+
|
|
153
|
+
const resolvedBase = path.join(projectRoot, 'node_modules', srcImportPath);
|
|
154
|
+
|
|
155
|
+
// Check for direct file match
|
|
156
|
+
const directMatch = findFileWithSuffix(resolvedBase, [
|
|
157
|
+
'.js',
|
|
158
|
+
'.jsx',
|
|
159
|
+
'.ts',
|
|
160
|
+
'.tsx',
|
|
161
|
+
]);
|
|
162
|
+
if (directMatch) {
|
|
163
|
+
return importPath + '.js';
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// Check for index file
|
|
167
|
+
const indexMatch = findFileWithSuffix(resolvedBase, [
|
|
168
|
+
'/index.js',
|
|
169
|
+
'/index.jsx',
|
|
170
|
+
'/index.ts',
|
|
171
|
+
'/index.tsx',
|
|
172
|
+
]);
|
|
173
|
+
if (indexMatch) {
|
|
174
|
+
return importPath + '/index.js';
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
return null;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Transform a third-party package import
|
|
182
|
+
* @param {string} importPath
|
|
183
|
+
* @returns {string | null}
|
|
184
|
+
*/
|
|
185
|
+
function transformThirdPartyImport(importPath) {
|
|
186
|
+
const resolvedBase = path.join(projectRoot, 'node_modules', importPath);
|
|
187
|
+
|
|
188
|
+
// Check for direct .js file
|
|
189
|
+
if (findFileWithSuffix(resolvedBase, ['.js'])) {
|
|
190
|
+
return importPath + '.js';
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// Check for index.js
|
|
194
|
+
if (findFileWithSuffix(resolvedBase, ['/index.js'])) {
|
|
195
|
+
return importPath + '/index.js';
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
return null;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
return {
|
|
202
|
+
name: 'transform-imports-plugin',
|
|
203
|
+
setup(api) {
|
|
204
|
+
api.transform(
|
|
205
|
+
{ test: /\.[jt]sx?$/, order: 'post' },
|
|
206
|
+
({ code, resourcePath }) => {
|
|
207
|
+
const transformedCode = code.replace(
|
|
208
|
+
importRegex,
|
|
209
|
+
(fullMatch, dynamicImport, staticImport) => {
|
|
210
|
+
const importPath = dynamicImport || staticImport;
|
|
211
|
+
|
|
212
|
+
// Early return for skippable imports
|
|
213
|
+
if (shouldSkipImport(importPath)) {
|
|
214
|
+
return fullMatch;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
// Check cache first
|
|
218
|
+
if (resolvedImportsCache.has(importPath)) {
|
|
219
|
+
const cached = resolvedImportsCache.get(importPath);
|
|
220
|
+
return cached
|
|
221
|
+
? fullMatch.replace(importPath, cached)
|
|
222
|
+
: fullMatch;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
const packageName = getPackageName(importPath);
|
|
226
|
+
|
|
227
|
+
// Skip third-party packages with exports field
|
|
228
|
+
if (
|
|
229
|
+
!isInternalPackage(packageName) &&
|
|
230
|
+
hasExportsField(packageName)
|
|
231
|
+
) {
|
|
232
|
+
logger.debug(`Skipping ${importPath} - uses exports field`);
|
|
233
|
+
resolvedImportsCache.set(importPath, null);
|
|
234
|
+
return fullMatch;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
// Transform based on package type
|
|
238
|
+
let newImportPath = null;
|
|
239
|
+
if (isInternalPackage(packageName)) {
|
|
240
|
+
newImportPath = transformInternalPackageImport(importPath);
|
|
241
|
+
} else {
|
|
242
|
+
newImportPath = transformThirdPartyImport(importPath);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
// Cache the result
|
|
246
|
+
resolvedImportsCache.set(importPath, newImportPath);
|
|
247
|
+
|
|
248
|
+
if (newImportPath) {
|
|
249
|
+
logger.debug(`Transformed import in ${resourcePath}`);
|
|
250
|
+
logger.debug(` ${importPath} => ${newImportPath}\n`);
|
|
251
|
+
return fullMatch.replace(importPath, newImportPath);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
return fullMatch;
|
|
255
|
+
}
|
|
256
|
+
);
|
|
257
|
+
|
|
258
|
+
return { code: transformedCode };
|
|
259
|
+
}
|
|
260
|
+
);
|
|
261
|
+
},
|
|
262
|
+
};
|
|
263
|
+
}
|
package/tsconfig.base.json
CHANGED
|
@@ -1,62 +1,24 @@
|
|
|
1
1
|
{
|
|
2
|
-
"extends": "./tsconfig.common.json",
|
|
3
2
|
"compilerOptions": {
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
"@digigov/nextjs/": ["./nextjs/src"],
|
|
26
|
-
"@digigov/nextjs": ["./nextjs/src"],
|
|
27
|
-
"@digigov/react-core/*": ["../libs-ui/react-core/src/*"],
|
|
28
|
-
"@digigov/react-core/": ["../libs-ui/react-core/src"],
|
|
29
|
-
"@digigov/react-core": ["../libs-ui/react-core/src"],
|
|
30
|
-
"@digigov/react-icons/*": ["../libs-ui/react-icons/src/*"],
|
|
31
|
-
"@digigov/react-icons/": ["../libs-ui/react-icons/src"],
|
|
32
|
-
"@digigov/react-icons": ["../libs-ui/react-icons/src"],
|
|
33
|
-
"@digigov/react-experimental/*": ["../libs-ui/react-experimental/src/*"],
|
|
34
|
-
"@digigov/react-experimental/": ["../libs-ui/react-experimental/src"],
|
|
35
|
-
"@digigov/react-experimental": ["../libs-ui/react-experimental/src"],
|
|
36
|
-
"@digigov/storybook/*": ["../examples/storybook/stories/*"],
|
|
37
|
-
"@uides/stepwise/*": ["./stepwise/src/*"],
|
|
38
|
-
"@uides/stepwise/": ["./stepwise/src"],
|
|
39
|
-
"@uides/stepwise": ["./stepwise/src"]
|
|
40
|
-
}
|
|
41
|
-
},
|
|
42
|
-
"include": [
|
|
43
|
-
"../../libs/auth/src/**/*.tsx",
|
|
44
|
-
"../../libs/auth/src/*.tsx",
|
|
45
|
-
"../../libs/text-search/src/**/*.tsx",
|
|
46
|
-
"../../libs/text-search/src/*.tsx",
|
|
47
|
-
"../../libs/text-search/src/**/*.ts",
|
|
48
|
-
"../../libs/text-search/src/*.ts",
|
|
49
|
-
"../../libs/form/src/**/*.(tsx|ts)",
|
|
50
|
-
"../../libs/form/src/*.(tsx|ts)",
|
|
51
|
-
"../../libs/form-dilosi-integration/src/**/*.(tsx|ts)",
|
|
52
|
-
"../../libs/form-dilosi-integration/src/*.(tsx|ts)",
|
|
53
|
-
"../../libs/ui-dilosi-integration/src/**/*.(tsx|ts)",
|
|
54
|
-
"../../libs/ui-dilosi-integration/src/*.(tsx|ts)",
|
|
55
|
-
"../../libs/ui/src/**/*.(tsx|ts)",
|
|
56
|
-
"../../libs/ui/src/*.(tsx|ts)",
|
|
57
|
-
"../../libs/auth/src/**/*.tsx",
|
|
58
|
-
"../../libs/auth/src/*.tsx",
|
|
59
|
-
"../../libs/nextjs/**/*.tsx",
|
|
60
|
-
"../../libs/nextjs/*.tsx"
|
|
61
|
-
]
|
|
3
|
+
"module": "ESNext",
|
|
4
|
+
"target": "es5",
|
|
5
|
+
"lib": ["es6", "dom", "es2019"],
|
|
6
|
+
"sourceMap": true,
|
|
7
|
+
"allowJs": true,
|
|
8
|
+
"jsx": "react",
|
|
9
|
+
"declaration": true,
|
|
10
|
+
"moduleResolution": "bundler",
|
|
11
|
+
"forceConsistentCasingInFileNames": true,
|
|
12
|
+
"noImplicitReturns": true,
|
|
13
|
+
"noImplicitThis": true,
|
|
14
|
+
"noImplicitAny": false,
|
|
15
|
+
"strictNullChecks": true,
|
|
16
|
+
"noUnusedLocals": true,
|
|
17
|
+
"noUnusedParameters": true,
|
|
18
|
+
"allowSyntheticDefaultImports": true,
|
|
19
|
+
"skipDefaultLibCheck": true,
|
|
20
|
+
"skipLibCheck": true,
|
|
21
|
+
"resolveJsonModule": true,
|
|
22
|
+
"isolatedModules": true
|
|
23
|
+
}
|
|
62
24
|
}
|