@common-stack/rollup-vite-utils 4.0.1-alpha.52 → 4.0.1-alpha.53
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,9 +1,12 @@
|
|
|
1
|
-
import { Plugin } from 'rollup';
|
|
2
1
|
interface AddJsExtensionOptions {
|
|
3
|
-
include?: string | string[];
|
|
4
|
-
exclude?: string | string[];
|
|
5
2
|
packages: string[] | '*';
|
|
6
3
|
needToAddIndexJs: string[];
|
|
7
4
|
}
|
|
8
|
-
declare const addJsExtensionToImportsPlugin: (options: AddJsExtensionOptions) =>
|
|
5
|
+
declare const addJsExtensionToImportsPlugin: (options: AddJsExtensionOptions) => {
|
|
6
|
+
name: string;
|
|
7
|
+
transform(code: string, id: string): {
|
|
8
|
+
code: any;
|
|
9
|
+
map: any;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
9
12
|
export default addJsExtensionToImportsPlugin;
|
|
@@ -1,48 +1,62 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
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
|
+
const traverse = traverseSource.default ?? traverseSource;
|
|
4
|
+
const generate = generateSource.default ?? generateSource;
|
|
5
|
+
const addJsExtensionToImportsPlugin = (options) => {
|
|
3
6
|
// Add known packages that need `/index.js` if they are not already included
|
|
4
7
|
const knownNeedToAddIndexJs = ['@apollo/client'];
|
|
5
8
|
const needToAddIndexJs = Array.from(new Set([...options.needToAddIndexJs, ...knownNeedToAddIndexJs]));
|
|
6
9
|
return {
|
|
7
|
-
name: '
|
|
10
|
+
name: 'add-js-extension-to-imports',
|
|
8
11
|
transform(code, id) {
|
|
9
|
-
|
|
12
|
+
// Only apply the transformation to .ts, .tsx, .js, and .jsx files
|
|
13
|
+
if (!/\.(tsx?|jsx?)$/.test(id))
|
|
10
14
|
return null;
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
//
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
15
|
+
const ast = parse(code, {
|
|
16
|
+
sourceType: 'module',
|
|
17
|
+
plugins: ['typescript', 'jsx'], // Adjusted to 'typescript' for .tsx files
|
|
18
|
+
});
|
|
19
|
+
traverse(ast, {
|
|
20
|
+
ImportDeclaration(path) {
|
|
21
|
+
const source = path.node.source.value;
|
|
22
|
+
// Function to extract package name from the import source
|
|
23
|
+
const getPackageName = (importPath) => {
|
|
24
|
+
if (importPath.startsWith('@')) {
|
|
25
|
+
// Scoped package
|
|
26
|
+
const match = importPath.match(/^(@[^/]+\/[^/]+)/);
|
|
27
|
+
return match ? match[1] : null;
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
// Normal package
|
|
31
|
+
const match = importPath.match(/^([^/]+)/);
|
|
32
|
+
return match ? match[1] : null;
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
const packageName = getPackageName(source);
|
|
36
|
+
// Determine if we should transform the import based on the package patterns
|
|
37
|
+
!source.startsWith('@');
|
|
38
|
+
const isInExceptionList = packageName && needToAddIndexJs.includes(packageName);
|
|
39
|
+
const isModularPackage = source.startsWith('@');
|
|
40
|
+
const hasAdditionalSlashes = isModularPackage && source.split('/').length > 2;
|
|
41
|
+
const shouldTransform = (options.packages === '*' && source.includes('/') && !isModularPackage) ||
|
|
42
|
+
(options.packages === '*' && isModularPackage && hasAdditionalSlashes) ||
|
|
43
|
+
(isModularPackage && isInExceptionList) ||
|
|
44
|
+
(packageName && options.packages.includes(packageName));
|
|
45
|
+
// Append ".js" or "/index.js" to imports if they match the criteria and don't already end with ".js"
|
|
46
|
+
if (shouldTransform && !source.endsWith('.js')) {
|
|
47
|
+
if (isInExceptionList) {
|
|
48
|
+
path.node.source.value = `${source}/index.js`;
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
path.node.source.value = `${source}.js`;
|
|
52
|
+
}
|
|
39
53
|
}
|
|
40
|
-
}
|
|
41
|
-
return match;
|
|
54
|
+
},
|
|
42
55
|
});
|
|
56
|
+
const output = generate(ast, {}, code);
|
|
43
57
|
return {
|
|
44
|
-
code:
|
|
45
|
-
map:
|
|
58
|
+
code: output.code,
|
|
59
|
+
map: output.map,
|
|
46
60
|
};
|
|
47
61
|
},
|
|
48
62
|
};
|
|
@@ -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":"2HAKA;AACA;AACA,MAAM,QAAQ,GAAI,cAAsB,CAAC,OAAO,IAAI,cAAc,CAAC;AACnE,MAAM,QAAQ,GAAI,cAAsB,CAAC,OAAO,IAAI,cAAc,CAAC;AAOnE,MAAM,6BAA6B,GAAG,CAAC,OAA8B,KAAI;;AAErE,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;IAEtG,OAAO;AACH,QAAA,IAAI,EAAE,6BAA6B;QACnC,SAAS,CAAC,IAAY,EAAE,EAAU,EAAA;;AAE9B,YAAA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A,MAAM,eAAe,GACjB,CAAC,OAAO,CAAC,QAAQ,KAAK,GAAG,IAAI,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,gBAAgB;yBACrE,OAAO,CAAC,QAAQ,KAAK,GAAG,IAAI,gBAAgB,IAAI,oBAAoB,CAAC;yBACrE,gBAAgB,IAAI,iBAAiB,CAAC;yBACtC,WAAW,IAAI,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC,CAAC;;oBAG5D,IAAI,eAAe,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE;wBAC5C,IAAI,iBAAiB,EAAE;4BACnB,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,GAAG,CAAA,EAAG,MAAM,CAAA,SAAA,CAAW,CAAC;yBACjD;6BAAM;4BACH,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,GAAG,CAAA,EAAG,MAAM,CAAA,GAAA,CAAK,CAAC;yBAC3C;qBACJ;iBACJ;AACJ,aAAA,CAAC,CAAC;YAEH,MAAM,MAAM,GAAG,QAAQ,CAAC,GAAG,EAAE,EAAE,EAAE,IAAI,CAAC,CAAC;YACvC,OAAO;gBACH,IAAI,EAAE,MAAM,CAAC,IAAI;gBACjB,GAAG,EAAE,MAAM,CAAC,GAAG;aAClB,CAAC;SACL;KACJ,CAAC;AACN"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@common-stack/rollup-vite-utils",
|
|
3
|
-
"version": "4.0.1-alpha.
|
|
3
|
+
"version": "4.0.1-alpha.53",
|
|
4
4
|
"description": "Client Module for react app",
|
|
5
5
|
"homepage": "https://github.com/cdmbase/fullstack-pro#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -54,5 +54,5 @@
|
|
|
54
54
|
"typescript": {
|
|
55
55
|
"definition": "lib/index.d.ts"
|
|
56
56
|
},
|
|
57
|
-
"gitHead": "
|
|
57
|
+
"gitHead": "911d04f767728db06d8fb370fa719ee8329cd814"
|
|
58
58
|
}
|