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

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,7 +1,9 @@
1
- export default function addJsExtensionToImportsPlugin(packages: any): {
1
+ import * as t from '@babel/types';
2
+ import { NodePath } from '@babel/traverse';
3
+ declare const addJsExtensionToImportsPlugin: (packages: string[] | '*') => {
2
4
  name: string;
3
- transform(code: any, id: any): {
4
- code: any;
5
- map: any;
5
+ visitor: {
6
+ ImportDeclaration(path: NodePath<t.ImportDeclaration>): void;
6
7
  };
7
8
  };
9
+ export default addJsExtensionToImportsPlugin;
@@ -1,39 +1,24 @@
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
- function addJsExtensionToImportsPlugin(packages) {
1
+ const addJsExtensionToImportsPlugin = (packages) => {
6
2
  return {
7
3
  name: 'add-js-extension-to-imports',
8
- transform(code, id) {
9
- // Only apply the transformation to TypeScript and JavaScript files
10
- if (!/\.tsx?$/.test(id))
11
- return null;
12
- const ast = parse(code, {
13
- sourceType: 'module',
14
- plugins: ['typescript', 'jsx'], // Adjusted to 'typescript' for .tsx files
15
- });
16
- traverse(ast, {
17
- ImportDeclaration(path) {
18
- const source = path.node.source.value;
19
- packages.forEach(pkg => {
20
- // Append ".js" to imports from specified packages if not already present
21
- if (source.startsWith(pkg) && !source.endsWith('.js')) {
22
- if (pkg === '@apollo/client' && (source === pkg || source === `${pkg}/`)) {
23
- path.node.source.value = source.endsWith('/') ? `${source}index.js` : `${source}/index.js`;
24
- }
25
- else {
26
- path.node.source.value = `${source}.js`;
27
- }
28
- }
29
- });
30
- },
31
- });
32
- const output = generate(ast, {}, code);
33
- return {
34
- code: output.code,
35
- map: output.map,
36
- };
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`;
16
+ }
17
+ else {
18
+ path.node.source.value = `${source}.js`;
19
+ }
20
+ }
21
+ },
37
22
  },
38
23
  };
39
- }export{addJsExtensionToImportsPlugin as default};//# sourceMappingURL=rollupPluginAddJsExtension.js.map
24
+ };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":"2HAIA;AACA;AACA,MAAM,QAAQ,GAAI,cAAsB,CAAC,OAAO,IAAI,cAAc,CAAC;AACnE,MAAM,QAAQ,GAAI,cAAsB,CAAC,OAAO,IAAI,cAAc,CAAC;AAE3C,SAAA,6BAA6B,CAAC,QAAQ,EAAA;IAC1D,OAAO;AACH,QAAA,IAAI,EAAE,6BAA6B;QACnC,SAAS,CAAC,IAAI,EAAE,EAAE,EAAA;;AAEd,YAAA,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC;AAAE,gBAAA,OAAO,IAAI,CAAC;AAErC,YAAA,MAAM,GAAG,GAAG,KAAK,CAAC,IAAI,EAAE;AACpB,gBAAA,UAAU,EAAE,QAAQ;AACpB,gBAAA,OAAO,EAAE,CAAC,YAAY,EAAE,KAAK,CAAC;AACjC,aAAA,CAAC,CAAC;YAEH,QAAQ,CAAC,GAAG,EAAE;AACV,gBAAA,iBAAiB,C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,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC;;AAGtC,gBAAA,MAAM,eAAe,GAAG,QAAQ,KAAK,GAAG,IAAI,QAAQ,CAAC,IAAI,CAAC,GAAG,IAAG;oBAC5D,MAAM,KAAK,GAAG,IAAI,MAAM,CAAC,CAAI,CAAA,EAAA,GAAG,CAAS,OAAA,CAAA,CAAC,CAAC;AAC3C,oBAAA,OAAO,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AAC9B,iBAAC,CAAC,CAAC;;gBAGH,IAAI,eAAe,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE;oBAC5C,IAAI,MAAM,KAAK,gBAAgB,IAAI,MAAM,KAAK,iBAAiB,EAAE;wBAC7D,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,GAAG,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAA,EAAG,MAAM,CAAA,QAAA,CAAU,GAAG,CAAA,EAAG,MAAM,CAAA,SAAA,CAAW,CAAC;qBAC9F;yBAAM;wBACH,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,GAAG,CAAA,EAAG,MAAM,CAAA,GAAA,CAAK,CAAC;qBAC3C;iBACJ;aACJ;AACJ,SAAA;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.49",
3
+ "version": "4.0.1-alpha.50",
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": "ef0042cfecdbb351d2c044370135f5fbb746c543"
57
+ "gitHead": "7690bdaa3b598355e3172a716dc4730382763bf0"
58
58
  }