@common-stack/rollup-vite-utils 4.0.1-alpha.50 → 4.0.1-alpha.52

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,9 @@
1
- import * as t from '@babel/types';
2
- import { NodePath } from '@babel/traverse';
3
- declare const addJsExtensionToImportsPlugin: (packages: string[] | '*') => {
4
- name: string;
5
- visitor: {
6
- ImportDeclaration(path: NodePath<t.ImportDeclaration>): void;
7
- };
8
- };
1
+ import { Plugin } from 'rollup';
2
+ interface AddJsExtensionOptions {
3
+ include?: string | string[];
4
+ exclude?: string | string[];
5
+ packages: string[] | '*';
6
+ needToAddIndexJs: string[];
7
+ }
8
+ declare const addJsExtensionToImportsPlugin: (options: AddJsExtensionOptions) => Plugin;
9
9
  export default addJsExtensionToImportsPlugin;
@@ -1,24 +1,49 @@
1
- const addJsExtensionToImportsPlugin = (packages) => {
1
+ import {createFilter}from'@rollup/pluginutils';const addJsExtensionToImportsPlugin = (options) => {
2
+ const filter = createFilter(options.include, options.exclude, { resolve: false });
3
+ // Add known packages that need `/index.js` if they are not already included
4
+ const knownNeedToAddIndexJs = ['@apollo/client'];
5
+ const needToAddIndexJs = Array.from(new Set([...options.needToAddIndexJs, ...knownNeedToAddIndexJs]));
2
6
  return {
3
- name: 'add-js-extension-to-imports',
4
- visitor: {
5
- ImportDeclaration(path) {
6
- const source = path.node.source.value;
7
- // Determine if we should transform the import based on the package patterns
8
- const shouldTransform = packages === '*' || packages.some(pkg => {
9
- const regex = new RegExp(`^${pkg}(/.*)?$`);
10
- return regex.test(source);
11
- });
12
- // Append ".js" to imports if they match the criteria and don't already end with ".js"
13
- if (shouldTransform && !source.endsWith('.js')) {
14
- if (source === '@apollo/client' || source === '@apollo/client/') {
15
- path.node.source.value = source.endsWith('/') ? `${source}index.js` : `${source}/index.js`;
7
+ name: 'rollup-plugin-add-js-extension',
8
+ transform(code, id) {
9
+ if (!filter(id))
10
+ return null;
11
+ const packageNameRegex = (importPath) => {
12
+ if (importPath.startsWith('@')) {
13
+ // Scoped package
14
+ const match = importPath.match(/^(@[^/]+\/[^/]+)/);
15
+ return match ? match[1] : null;
16
+ }
17
+ else {
18
+ // Normal package
19
+ const match = importPath.match(/^([^/]+)/);
20
+ return match ? match[1] : null;
21
+ }
22
+ };
23
+ const transformedCode = code.replace(/import\s+(['"])([^'"]+)\1/g, (match, quote, importPath) => {
24
+ const packageName = packageNameRegex(importPath);
25
+ !importPath.startsWith('@');
26
+ const isInExceptionList = packageName && needToAddIndexJs.includes(packageName);
27
+ const isModularPackage = importPath.startsWith('@');
28
+ const hasAdditionalSlashes = isModularPackage && importPath.split('/').length > 2;
29
+ const shouldTransform = (options.packages === '*' && importPath.includes('/') && !isModularPackage) ||
30
+ (options.packages === '*' && isModularPackage && hasAdditionalSlashes) ||
31
+ (isModularPackage && isInExceptionList) ||
32
+ (packageName && options.packages.includes(packageName));
33
+ if (shouldTransform && !importPath.endsWith('.js')) {
34
+ if (isInExceptionList) {
35
+ return `import ${quote}${importPath}/index.js${quote}`;
16
36
  }
17
37
  else {
18
- path.node.source.value = `${source}.js`;
38
+ return `import ${quote}${importPath}.js${quote}`;
19
39
  }
20
40
  }
21
- },
41
+ return match;
42
+ });
43
+ return {
44
+ code: transformedCode,
45
+ map: null,
46
+ };
22
47
  },
23
48
  };
24
49
  };export{addJsExtensionToImportsPlugin as default};//# sourceMappingURL=rollupPluginAddJsExtension.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"rollupPluginAddJsExtension.js","sources":["../../src/rollup/rollupPluginAddJsExtension.ts"],"sourcesContent":[null],"names":[],"mappings":"AAGA,MAAM,6BAA6B,GAAG,CAAC,QAAwB,KAAI;IAC/D,OAAO;AACH,QAAA,IAAI,EAAE,6BAA6B;AACnC,QAAA,OAAO,EAAE;AACL,YAAA,iBAAiB,CAAC,IAAmC,EAAA;gBACjD,MAAM,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,KA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,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,gBAAgB;qBACzE,OAAO,CAAC,QAAQ,KAAK,GAAG,IAAI,gBAAgB,IAAI,oBAAoB,CAAC;qBACrE,gBAAgB,IAAI,iBAAiB,CAAC;qBACtC,WAAW,IAAI,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC,CAAC;gBAE5D,IAAI,eAAe,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE;oBAChD,IAAI,iBAAiB,EAAE;AACnB,wBAAA,OAAO,UAAU,KAAK,CAAA,EAAG,UAAU,CAAY,SAAA,EAAA,KAAK,EAAE,CAAC;qBAC1D;yBAAM;AACH,wBAAA,OAAO,UAAU,KAAK,CAAA,EAAG,UAAU,CAAM,GAAA,EAAA,KAAK,EAAE,CAAC;qBACpD;iBACJ;AAED,gBAAA,OAAO,KAAK,CAAC;AACjB,aAAC,CAAC,CAAC;YAEH,OAAO;AACH,gBAAA,IAAI,EAAE,eAAe;AACrB,gBAAA,GAAG,EAAE,IAAI;aACZ,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.50",
3
+ "version": "4.0.1-alpha.52",
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": "7690bdaa3b598355e3172a716dc4730382763bf0"
57
+ "gitHead": "14099d8395f365c088145a6834371efc6b28ce15"
58
58
  }
@@ -1 +0,0 @@
1
- export {};