@common-stack/rollup-vite-utils 4.0.1-alpha.61 → 4.0.1-alpha.63
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.
|
@@ -1,59 +1,58 @@
|
|
|
1
1
|
import {parse}from'@babel/parser';import generateSource from'@babel/generator';import traverseSource from'@babel/traverse';// to support esm default
|
|
2
|
-
// https://github.com/babel/babel/issues/15269#issuecomment-1505804243
|
|
3
2
|
const traverse = traverseSource.default ?? traverseSource;
|
|
4
3
|
const generate = generateSource.default ?? generateSource;
|
|
5
4
|
const addJsExtensionToImportsPlugin = (options) => {
|
|
6
|
-
// Add known packages that need `/index.js` if they are not already included
|
|
7
5
|
const knownNeedToAddIndexJs = ['@apollo/client'];
|
|
8
6
|
const needToAddIndexJs = Array.from(new Set([...options.needToAddIndexJs, ...knownNeedToAddIndexJs]));
|
|
7
|
+
const createRegexFromPackagePattern = (pattern) => {
|
|
8
|
+
const escapedPattern = pattern.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // Escape special characters
|
|
9
|
+
return new RegExp(`^${escapedPattern.replace(/\\\*/g, '.*')}`);
|
|
10
|
+
};
|
|
9
11
|
return {
|
|
10
12
|
name: 'add-js-extension-to-imports',
|
|
11
13
|
transform(code, id) {
|
|
12
|
-
// Only apply the transformation to .ts, .tsx, .js, and .jsx files
|
|
13
14
|
if (!/\.(tsx?|jsx?)$/.test(id))
|
|
14
15
|
return null;
|
|
15
16
|
const ast = parse(code, {
|
|
16
17
|
sourceType: 'module',
|
|
17
|
-
plugins: ['typescript', 'jsx'],
|
|
18
|
+
plugins: ['typescript', 'jsx'],
|
|
18
19
|
});
|
|
19
20
|
traverse(ast, {
|
|
20
21
|
ImportDeclaration(path) {
|
|
21
22
|
const source = path.node.source.value;
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
(options.excludeImports && options.excludeImports.includes(source)))
|
|
23
|
+
if (/\.[a-z]+(\?.*)?$/.test(source) || (options.excludeImports && options.excludeImports.includes(source))) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
if (source.startsWith('./') || source.startsWith('../'))
|
|
27
27
|
return;
|
|
28
|
-
// Function to extract package name from the import source
|
|
29
28
|
const getPackageName = (importPath) => {
|
|
30
29
|
if (importPath.startsWith('@')) {
|
|
31
|
-
// Scoped package
|
|
32
30
|
const match = importPath.match(/^(@[^/]+\/[^/]+)/);
|
|
33
31
|
return match ? match[1] : null;
|
|
34
32
|
}
|
|
35
33
|
else {
|
|
36
|
-
// Normal package
|
|
37
34
|
const match = importPath.match(/^([^/]+)/);
|
|
38
35
|
return match ? match[1] : null;
|
|
39
36
|
}
|
|
40
37
|
};
|
|
41
38
|
const packageName = getPackageName(source);
|
|
42
|
-
|
|
43
|
-
|
|
39
|
+
const shouldTransform = options.packages === '*' || options.packages.some(pkgPattern => {
|
|
40
|
+
const regex = createRegexFromPackagePattern(pkgPattern);
|
|
41
|
+
return regex.test(source);
|
|
42
|
+
});
|
|
43
|
+
if (!shouldTransform) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
44
46
|
const isInExceptionList = packageName && needToAddIndexJs.includes(packageName);
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
const shouldTransform = (options.packages === '*' && source.includes('/') && !isModularPackage) ||
|
|
48
|
-
(options.packages === '*' && isModularPackage && hasAdditionalSlashes) ||
|
|
49
|
-
(isModularPackage && isInExceptionList) ||
|
|
50
|
-
(packageName && options.packages.includes(packageName));
|
|
51
|
-
// Append ".js" or "/index.js" to imports if they match the criteria and don't already end with ".js"
|
|
52
|
-
if (shouldTransform && !source.endsWith('.js')) {
|
|
47
|
+
const slashCount = (source.match(/\//g) || []).length;
|
|
48
|
+
if (shouldTransform) {
|
|
53
49
|
if (isInExceptionList) {
|
|
54
50
|
path.node.source.value = `${source}/index.js`;
|
|
55
51
|
}
|
|
56
|
-
else {
|
|
52
|
+
else if (source.startsWith('@') && slashCount >= 2) {
|
|
53
|
+
path.node.source.value = `${source}.js`;
|
|
54
|
+
}
|
|
55
|
+
else if (!source.startsWith('@') && slashCount >= 1) {
|
|
57
56
|
path.node.source.value = `${source}.js`;
|
|
58
57
|
}
|
|
59
58
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rollupPluginAddJsExtension.js","sources":["../../src/rollup/rollupPluginAddJsExtension.ts"],"sourcesContent":[null],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"rollupPluginAddJsExtension.js","sources":["../../src/rollup/rollupPluginAddJsExtension.ts"],"sourcesContent":[null],"names":[],"mappings":"2HAIA;AACA,MAAM,QAAQ,GAAI,cAAsB,CAAC,OAAO,IAAI,cAAc,CAAC;AACnE,MAAM,QAAQ,GAAI,cAAsB,CAAC,OAAO,IAAI,cAAc,CAAC;AAQnE,MAAM,6BAA6B,GAAG,CAAC,OAA8B,KAAI;AACrE,IAAA,MAAM,qBAAqB,GAAG,CAAC,gBAAgB,CAAC,CAAC;IACjD,MAAM,gBAAgB,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC,GAAG,OAAO,CAAC,gBAAgB,EAAE,GAAG,qBAAqB,CAAC,CAAC,CAAC,CAAC;AAEtG,IAAA,MAAM,6BAA6B,GAAG,CAAC,OAAe,KAAI;AACtD,QAAA,MAAM,cAAc,GAAG,OAAO,CAAC,OAAO,CAAC,qBAAqB,EAAE,MAAM,CAAC,CAAC;AACtE,QAAA,OAAO,IAAI,MAAM,CAAC,CAAA,CAAA,EAAI,cAAc,CAAC,OAAO,CAAC,OAAO,EAAE,IAAI,CAAC,CAAA,CAAE,CAAC,CAAC;AACnE,KAAC,CAAC;IAEF,OAAO;AACH,QAAA,IAAI,EAAE,6BAA6B;QACnC,SAAS,CAAC,IAAY,EAAE,EAAU,EAAA;AAC9B,YAAA,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,EAAE,CAAC;AAAE,gBAAA,OAAO,IAAI,CAAC;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
|
{
|
|
2
2
|
"name": "@common-stack/rollup-vite-utils",
|
|
3
|
-
"version": "4.0.1-alpha.
|
|
3
|
+
"version": "4.0.1-alpha.63",
|
|
4
4
|
"description": "Client Module for react app",
|
|
5
5
|
"homepage": "https://github.com/cdmbase/fullstack-pro#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -34,6 +34,7 @@
|
|
|
34
34
|
"@common-stack/core": "4.0.1-alpha.31",
|
|
35
35
|
"dot-prop": "^9.0.0",
|
|
36
36
|
"js-sha256": "^0.11.0",
|
|
37
|
+
"minimatch": "^9.0.5",
|
|
37
38
|
"ts-deepmerge": "^7.0.0"
|
|
38
39
|
},
|
|
39
40
|
"devDependencies": {
|
|
@@ -54,5 +55,5 @@
|
|
|
54
55
|
"typescript": {
|
|
55
56
|
"definition": "lib/index.d.ts"
|
|
56
57
|
},
|
|
57
|
-
"gitHead": "
|
|
58
|
+
"gitHead": "709bb271ca8a2ded2b57766e6cfe8b5f47eb802d"
|
|
58
59
|
}
|