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

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,6 +1,6 @@
1
1
  import * as t from '@babel/types';
2
2
  import { NodePath } from '@babel/traverse';
3
- declare const addJsExtensionToImportsPlugin: (packages: string[] | '*') => {
3
+ declare const addJsExtensionToImportsPlugin: (packages: string[] | '*', needToAddIndexJs?: string[]) => {
4
4
  name: string;
5
5
  visitor: {
6
6
  ImportDeclaration(path: NodePath<t.ImportDeclaration>): void;
@@ -1,18 +1,39 @@
1
- const addJsExtensionToImportsPlugin = (packages) => {
1
+ const addJsExtensionToImportsPlugin = (packages, needToAddIndexJs = []) => {
2
+ // Add known packages that need `/index.js` if they are not already included
3
+ const knownNeedToAddIndexJs = ['@apollo/client'];
4
+ needToAddIndexJs = Array.from(new Set([...needToAddIndexJs, ...knownNeedToAddIndexJs]));
2
5
  return {
3
6
  name: 'add-js-extension-to-imports',
4
7
  visitor: {
5
8
  ImportDeclaration(path) {
6
9
  const source = path.node.source.value;
10
+ // Function to extract package name from the import source
11
+ const getPackageName = (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 packageName = getPackageName(source);
7
24
  // 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"
25
+ !source.startsWith('@');
26
+ const isInExceptionList = packageName && needToAddIndexJs.includes(packageName);
27
+ const isModularPackage = source.startsWith('@');
28
+ const hasAdditionalSlashes = isModularPackage && source.split('/').length > 2;
29
+ const shouldTransform = (packages === '*' && source.includes('/') && !isModularPackage) ||
30
+ (packages === '*' && isModularPackage && hasAdditionalSlashes) ||
31
+ (isModularPackage && isInExceptionList) ||
32
+ (packageName && packages.includes(packageName));
33
+ // Append ".js" or "/index.js" to imports if they match the criteria and don't already end with ".js"
13
34
  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`;
35
+ if (isInExceptionList) {
36
+ path.node.source.value = `${source}/index.js`;
16
37
  }
17
38
  else {
18
39
  path.node.source.value = `${source}.js`;
@@ -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,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,CAA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G,IAAI,CAAC;qBAClC;AACL,iBAAC,CAAC;AAEF,gBAAA,MAAM,WAAW,GAAG,cAAc,CAAC,MAAM,CAAC,CAAC;;gBAGnB,CAAC,MAAM,CAAC,UAAU,CAAC,GAAG,EAAE;gBAChD,MAAM,iBAAiB,GAAG,WAAW,IAAI,gBAAgB,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;gBAChF,MAAM,gBAAgB,GAAG,MAAM,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;AAChD,gBAAA,MAAM,oBAAoB,GAAG,gBAAgB,IAAI,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;AAE9E,gBAAA,MAAM,eAAe,GACjB,CAAC,QAAQ,KAAK,GAAG,IAAI,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,gBAAgB;AAC9D,qBAAC,QAAQ,KAAK,GAAG,IAAI,gBAAgB,IAAI,oBAAoB,CAAC;qBAC7D,gBAAgB,IAAI,iBAAiB,CAAC;qBACtC,WAAW,IAAI,QAAQ,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC,CAAC;;gBAGpD,IAAI,eAAe,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE;oBAC5C,IAAI,iBAAiB,EAAE;wBACnB,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,GAAG,CAAA,EAAG,MAAM,CAAA,SAAA,CAAW,CAAC;qBACjD;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.50",
3
+ "version": "4.0.1-alpha.51",
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": "e03f5976e7390fb98a898aedf97ad692ef54f78b"
58
58
  }