xanix 1.0.19 → 1.0.21
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.
- package/dist/bin/bundler/cache/buildCache.js +9 -11
- package/dist/bin/bundler/cache/index.js +70 -116
- package/dist/bin/bundler/cache/utils.d.ts +3 -2
- package/dist/bin/bundler/cache/utils.js +27 -24
- package/dist/bin/bundler/client/build.js +1 -1
- package/dist/bin/bundler/client/plugins/Transformer/TransformCacheFunction copy.d.ts +3 -0
- package/dist/bin/bundler/client/plugins/Transformer/TransformCacheFunction copy.js +32 -0
- package/dist/bin/bundler/client/plugins/Transformer/TransformCacheFunction.d.ts +1 -1
- package/dist/bin/bundler/client/plugins/Transformer/TransformCacheFunction.js +1 -1
- package/dist/bin/bundler/client/plugins/Transformer/TransformCreateSession.d.ts +1 -1
- package/dist/bin/bundler/client/plugins/Transformer/TransformCreateSession.js +1 -1
- package/dist/bin/bundler/client/plugins/Transformer/TransformDevModule.d.ts +13 -0
- package/dist/bin/bundler/client/plugins/Transformer/{transformModuleCache.js → TransformDevModule.js} +6 -18
- package/dist/bin/bundler/client/plugins/Transformer/TransformServerFunction.d.ts +1 -1
- package/dist/bin/bundler/client/plugins/Transformer/TransformServerFunction.js +1 -1
- package/dist/bin/bundler/client/plugins/Transformer/cacheFunctionReplacer.d.ts +3 -0
- package/dist/bin/bundler/client/plugins/Transformer/cacheFunctionReplacer.js +32 -0
- package/dist/bin/bundler/client/plugins/Transformer/cacheFunctionTransformer.d.ts +3 -0
- package/dist/bin/bundler/client/plugins/Transformer/cacheFunctionTransformer.js +32 -0
- package/dist/bin/bundler/client/plugins/Transformer/serverFunctionReplacer.d.ts +3 -0
- package/dist/bin/bundler/client/plugins/Transformer/serverFunctionReplacer.js +32 -0
- package/dist/bin/bundler/client/plugins/Transformer/useServerReplacer.d.ts +3 -0
- package/dist/bin/bundler/client/plugins/Transformer/useServerReplacer.js +42 -0
- package/dist/bin/bundler/client/plugins/Transformer.js +4 -2
- package/dist/bin/bundler/client/plugins/XanixAppRoot.d.ts +2 -0
- package/dist/bin/bundler/client/plugins/XanixAppRoot.js +46 -0
- package/dist/bin/bundler/client/plugins/XanixPage.js +30 -0
- package/dist/bin/bundler/client/plugins/XanixPages.js +8 -8
- package/dist/bin/bundler/client/plugins/replacer/cacheFunctionReplacer.d.ts +1 -1
- package/dist/bin/bundler/client/plugins/replacer/cacheFunctionReplacer.js +5 -1
- package/dist/bin/bundler/client/plugins/replacer/serverFunctionReplacer.d.ts +1 -1
- package/dist/bin/bundler/client/plugins/replacer/serverFunctionReplacer.js +5 -1
- package/dist/bin/bundler/client/plugins/replacer/useServerReplacer.d.ts +1 -1
- package/dist/bin/bundler/client/plugins/replacer/useServerReplacer.js +7 -3
- package/dist/bin/bundler/server/build.js +1 -1
- package/dist/bin/bundler/server/plugins/Transformer/TransformCacheFunction copy.d.ts +3 -0
- package/dist/bin/bundler/server/plugins/Transformer/TransformCacheFunction copy.js +32 -0
- package/dist/bin/bundler/server/plugins/Transformer/TransformCacheFunction.d.ts +1 -1
- package/dist/bin/bundler/server/plugins/Transformer/TransformCacheFunction.js +1 -1
- package/dist/bin/bundler/server/plugins/Transformer/TransformCreateSession.d.ts +1 -1
- package/dist/bin/bundler/server/plugins/Transformer/TransformCreateSession.js +1 -1
- package/dist/bin/bundler/server/plugins/Transformer/TransformExpressFunction.d.ts +1 -1
- package/dist/bin/bundler/server/plugins/Transformer/TransformExpressFunction.js +1 -1
- package/dist/bin/bundler/server/plugins/Transformer/TransformPage.js +1 -1
- package/dist/bin/bundler/server/plugins/Transformer/TransformServerFunction.d.ts +1 -1
- package/dist/bin/bundler/server/plugins/Transformer/TransformServerFunction.js +1 -1
- package/dist/bin/bundler/server/plugins/Transformer/cacheFunctionReplacer.d.ts +3 -0
- package/dist/bin/bundler/server/plugins/Transformer/cacheFunctionReplacer.js +32 -0
- package/dist/bin/bundler/server/plugins/Transformer/expressFunctionReplace.d.ts +3 -0
- package/dist/bin/bundler/server/plugins/Transformer/expressFunctionReplace.js +24 -0
- package/dist/bin/bundler/server/plugins/Transformer/pageReplacer.d.ts +4 -0
- package/dist/bin/bundler/server/plugins/Transformer/pageReplacer.js +31 -0
- package/dist/bin/bundler/server/plugins/Transformer/serverFunctionReplacer.d.ts +3 -0
- package/dist/bin/bundler/server/plugins/Transformer/serverFunctionReplacer.js +32 -0
- package/dist/bin/bundler/server/plugins/Transformer/useServerReplacer.d.ts +3 -0
- package/dist/bin/bundler/server/plugins/Transformer/useServerReplacer.js +42 -0
- package/dist/bin/bundler/server/plugins/Transformer copy.js +3 -3
- package/dist/bin/bundler/server/plugins/Transformer.js +2 -2
- package/dist/bin/bundler/server/plugins/replacer/cacheFunctionReplacer.d.ts +1 -1
- package/dist/bin/bundler/server/plugins/replacer/cacheFunctionReplacer.js +5 -1
- package/dist/bin/bundler/server/plugins/replacer/serverFunctionReplacer copy.d.ts +3 -0
- package/dist/bin/bundler/server/plugins/replacer/serverFunctionReplacer copy.js +26 -0
- package/dist/bin/bundler/server/plugins/replacer/serverFunctionReplacer.d.ts +1 -1
- package/dist/bin/bundler/server/plugins/replacer/serverFunctionReplacer.js +5 -1
- package/dist/bin/bundler/server/plugins/replacer/serverReplacer.d.ts +3 -0
- package/dist/bin/bundler/server/plugins/replacer/serverReplacer.js +26 -0
- package/dist/bin/bundler/server/plugins/replacer/useServerReplacer.d.ts +2 -2
- package/dist/bin/bundler/server/plugins/replacer/useServerReplacer.js +9 -5
- package/dist/bin/cli/dev.js +85 -71
- package/dist/bin/cli/start/index.d.ts +4 -1
- package/dist/bin/cli/start/index.js +60 -9
- package/dist/bin/finder/callbackReplacer.d.ts +2 -0
- package/dist/bin/finder/callbackReplacer.js +52 -0
- package/dist/bin/finder/findImport.d.ts +9 -0
- package/dist/bin/finder/findImport.js +50 -0
- package/dist/bin/finder/findImports.d.ts +16 -0
- package/dist/bin/finder/findImports.js +45 -0
- package/dist/bin/finder/findPage.d.ts +9 -0
- package/dist/bin/finder/findPage.js +30 -0
- package/dist/bin/finder/importFinder.d.ts +9 -0
- package/dist/bin/finder/importFinder.js +50 -0
- package/dist/bin/finder/pageFinder.d.ts +9 -0
- package/dist/bin/finder/pageFinder.js +30 -0
- package/dist/bin/finder/stripComments.d.ts +3 -0
- package/dist/bin/finder/stripComments.js +15 -0
- package/dist/bin/include/path.d.ts +5 -1
- package/dist/bin/include/path.js +15 -1
- package/dist/bin/include/sendFinder.d.ts +4 -1
- package/dist/bin/include/sendFinder.js +88 -53
- package/dist/bin/index.js +0 -0
- package/dist/bin/modifier/callbackReplacer.js +35 -80
- package/dist/bin/modifier/findImports.d.ts +16 -0
- package/dist/bin/modifier/findImports.js +45 -0
- package/dist/bin/modifier/importFinder.js +44 -63
- package/dist/bin/modifier/pageFinder.d.ts +1 -1
- package/dist/bin/modifier/pageFinder.js +19 -124
- package/dist/bin/modifier/sendFinder.d.ts +9 -0
- package/dist/bin/modifier/sendFinder.js +135 -0
- package/dist/bin/modifier/sriptCommnet.d.ts +1 -0
- package/dist/bin/modifier/sriptCommnet.js +12 -5
- package/dist/bin/modifier/stripComments.d.ts +3 -0
- package/dist/bin/modifier/stripComments.js +15 -0
- package/dist/bin/plugins/XanixAssets.js +2 -2
- package/dist/bin/plugins/XanixCss.js +13 -13
- package/dist/bin/plugins/XanixDocument.js +4 -4
- package/dist/components/Head.js +1 -1
- package/dist/hooks/encript.d.ts +2 -0
- package/dist/hooks/encript.js +13 -0
- package/dist/hooks/server.js +2 -2
- package/dist/hooks/session.js +2 -2
- package/dist/index.js +0 -0
- package/dist/libs/encoder.d.ts +2 -0
- package/dist/libs/encoder.js +13 -0
- package/dist/libs/encript.d.ts +2 -0
- package/dist/libs/encript.js +30 -0
- package/dist/navigate.js +1 -1
- package/dist/server/express/Router.js +4 -4
- package/dist/server/express/page.d.ts +1 -1
- package/dist/server/express/page.js +1 -1
- package/dist/types/assets.d.ts +72 -72
- package/dist/types/express.d.ts +11 -11
- package/dist/types/globals.d.ts +18 -18
- package/dist/types/xanix-virtual.d.ts +35 -35
- package/package.json +57 -60
- package/dist/bin/bundler/Cache.d.ts +0 -1
- package/dist/bin/bundler/Cache.js +0 -210
- package/dist/bin/bundler/External.d.ts +0 -3
- package/dist/bin/bundler/External.js +0 -6
- package/dist/bin/bundler/buildClient.d.ts +0 -3
- package/dist/bin/bundler/buildClient.js +0 -42
- package/dist/bin/bundler/buildServer.d.ts +0 -7
- package/dist/bin/bundler/buildServer.js +0 -50
- package/dist/bin/bundler/cache/plugin/Transformer.d.ts +0 -3
- package/dist/bin/bundler/cache/plugin/Transformer.js +0 -42
- package/dist/bin/bundler/client/plugins/Transformer/TransformExpress.d.ts +0 -9
- package/dist/bin/bundler/client/plugins/Transformer/TransformExpress.js +0 -26
- package/dist/bin/bundler/client/plugins/Transformer/TransformPage.d.ts +0 -29
- package/dist/bin/bundler/client/plugins/Transformer/TransformPage.js +0 -77
- package/dist/bin/bundler/client/plugins/Transformer/TransformReactContext.d.ts +0 -17
- package/dist/bin/bundler/client/plugins/Transformer/TransformReactContext.js +0 -101
- package/dist/bin/bundler/client/plugins/Transformer/transformModuleCache.d.ts +0 -15
- package/dist/bin/bundler/client/plugins/Transformer copy.d.ts +0 -3
- package/dist/bin/bundler/client/plugins/Transformer copy.js +0 -70
- package/dist/bin/bundler/client/plugins/VirtualDev.d.ts +0 -2
- package/dist/bin/bundler/client/plugins/VirtualDev.js +0 -34
- package/dist/bin/bundler/client/plugins/XanixReactRefresh.d.ts +0 -2
- package/dist/bin/bundler/client/plugins/XanixReactRefresh.js +0 -22
- package/dist/bin/bundler/config/defines.d.ts +0 -20
- package/dist/bin/bundler/config/defines.js +0 -21
- package/dist/bin/bundler/config/external.d.ts +0 -1
- package/dist/bin/bundler/config/external.js +0 -12
- package/dist/bin/bundler/config/loadEnv.d.ts +0 -20
- package/dist/bin/bundler/config/loadEnv.js +0 -48
- package/dist/bin/bundler/config/output.d.ts +0 -10
- package/dist/bin/bundler/config/output.js +0 -52
- package/dist/bin/bundler/externalResolver-dep.d.ts +0 -3
- package/dist/bin/bundler/externalResolver-dep.js +0 -203
- package/dist/bin/bundler/externalResolver.d.ts +0 -3
- package/dist/bin/bundler/externalResolver.js +0 -203
- package/dist/bin/bundler/plugins/TransformServer/TransformExpress.d.ts +0 -9
- package/dist/bin/bundler/plugins/TransformServer/TransformExpress.js +0 -26
- package/dist/bin/bundler/plugins/TransformServer/TransformPage.d.ts +0 -25
- package/dist/bin/bundler/plugins/TransformServer/TransformPage.js +0 -79
- package/dist/bin/bundler/plugins/TransformServer/index.d.ts +0 -3
- package/dist/bin/bundler/plugins/TransformServer/index.js +0 -103
- package/dist/bin/bundler/plugins/XanixAssets.d.ts +0 -5
- package/dist/bin/bundler/plugins/XanixAssets.js +0 -51
- package/dist/bin/bundler/plugins/XanixCacheDeps-dep.d.ts +0 -2
- package/dist/bin/bundler/plugins/XanixCacheDeps-dep.js +0 -150
- package/dist/bin/bundler/plugins/XanixCacheDeps.d.ts +0 -2
- package/dist/bin/bundler/plugins/XanixCacheDeps.js +0 -150
- package/dist/bin/bundler/plugins/XanixDocument/index.js +0 -53
- package/dist/bin/bundler/plugins/XanixEntryFinder/finder.d.ts +0 -11
- package/dist/bin/bundler/plugins/XanixEntryFinder/finder.js +0 -149
- package/dist/bin/bundler/plugins/XanixEntryFinder/index.d.ts +0 -6
- package/dist/bin/bundler/plugins/XanixEntryFinder/index.js +0 -37
- package/dist/bin/bundler/plugins/XanixEntryFinder-dep/finder.d.ts +0 -11
- package/dist/bin/bundler/plugins/XanixEntryFinder-dep/finder.js +0 -149
- package/dist/bin/bundler/plugins/XanixEntryFinder-dep/index.d.ts +0 -6
- package/dist/bin/bundler/plugins/XanixEntryFinder-dep/index.js +0 -37
- package/dist/bin/bundler/plugins/XanixEnv.d.ts +0 -15
- package/dist/bin/bundler/plugins/XanixEnv.js +0 -44
- package/dist/bin/bundler/plugins/XanixPageTransform/index.d.ts +0 -2
- package/dist/bin/bundler/plugins/XanixPageTransform/index.js +0 -62
- package/dist/bin/bundler/plugins/XanixPageTransform/transformer copy.d.ts +0 -18
- package/dist/bin/bundler/plugins/XanixPageTransform/transformer copy.js +0 -414
- package/dist/bin/bundler/plugins/XanixPageTransform/transformer.d.ts +0 -23
- package/dist/bin/bundler/plugins/XanixPageTransform/transformer.js +0 -589
- package/dist/bin/bundler/plugins/XanixReactRefresh copy.d.ts +0 -2
- package/dist/bin/bundler/plugins/XanixReactRefresh copy.js +0 -121
- package/dist/bin/bundler/plugins/XanixReactRefresh.d.ts +0 -2
- package/dist/bin/bundler/plugins/XanixReactRefresh.js +0 -170
- package/dist/bin/bundler/plugins/XanixResolveCacheDeps/BuildClientCache.d.ts +0 -11
- package/dist/bin/bundler/plugins/XanixResolveCacheDeps/BuildClientCache.js +0 -129
- package/dist/bin/bundler/plugins/XanixResolveCacheDeps/index copy.d.ts +0 -15
- package/dist/bin/bundler/plugins/XanixResolveCacheDeps/index copy.js +0 -228
- package/dist/bin/bundler/plugins/XanixResolveCacheDeps/index.d.ts +0 -7
- package/dist/bin/bundler/plugins/XanixResolveCacheDeps/index.js +0 -166
- package/dist/bin/bundler/plugins/XanixResolveCacheDeps-dep/BuildClientCache.d.ts +0 -11
- package/dist/bin/bundler/plugins/XanixResolveCacheDeps-dep/BuildClientCache.js +0 -129
- package/dist/bin/bundler/plugins/XanixResolveCacheDeps-dep/index.d.ts +0 -5
- package/dist/bin/bundler/plugins/XanixResolveCacheDeps-dep/index.js +0 -26
- package/dist/bin/bundler/plugins/XanixResolver.d.ts +0 -11
- package/dist/bin/bundler/plugins/XanixResolver.js +0 -55
- package/dist/bin/bundler/plugins/XanixServerTransform.d.ts +0 -5
- package/dist/bin/bundler/plugins/XanixServerTransform.js +0 -207
- package/dist/bin/bundler/plugins/XanixTransform.d.ts +0 -3
- package/dist/bin/bundler/plugins/XanixTransform.js +0 -23
- package/dist/bin/bundler/plugins/XanixTsconfigAlias.d.ts +0 -19
- package/dist/bin/bundler/plugins/XanixTsconfigAlias.js +0 -197
- package/dist/bin/bundler/plugins/XanixUseServer.d.ts +0 -7
- package/dist/bin/bundler/plugins/XanixUseServer.js +0 -445
- package/dist/bin/bundler/plugins/plugins.d.ts +0 -9
- package/dist/bin/bundler/plugins/plugins.js +0 -37
- package/dist/bin/bundler/requireCache.d.ts +0 -3
- package/dist/bin/bundler/requireCache.js +0 -85
- package/dist/bin/bundler/server/plugins/ServerAction.d.ts +0 -3
- package/dist/bin/bundler/server/plugins/ServerAction.js +0 -9
- package/dist/bin/bundler/server/plugins/Transformer/ServerAction.d.ts +0 -11
- package/dist/bin/bundler/server/plugins/Transformer/ServerAction.js +0 -28
- package/dist/bin/bundler/server/plugins/Transformer/TransformExpress copy.d.ts +0 -11
- package/dist/bin/bundler/server/plugins/Transformer/TransformExpress copy.js +0 -22
- package/dist/bin/bundler/server/plugins/Transformer/TransformExpress.d.ts +0 -10
- package/dist/bin/bundler/server/plugins/Transformer/TransformExpress.js +0 -19
- package/dist/bin/bundler/server/plugins/Transformer/TransformReactContext.d.ts +0 -17
- package/dist/bin/bundler/server/plugins/Transformer/TransformReactContext.js +0 -101
- package/dist/bin/bundler/server/plugins/Transformer/TransformServerAction copy.d.ts +0 -14
- package/dist/bin/bundler/server/plugins/Transformer/TransformServerAction copy.js +0 -38
- package/dist/bin/bundler/server/types.d.ts +0 -5
- package/dist/bin/bundler/server/types.js +0 -1
- package/dist/bin/bundler/watchClient.d.ts +0 -12
- package/dist/bin/bundler/watchClient.js +0 -104
- package/dist/bin/bundler/watchServer.d.ts +0 -10
- package/dist/bin/bundler/watchServer.js +0 -139
- package/dist/bin/cli/dev/dev.d.ts +0 -2
- package/dist/bin/cli/dev/dev.js +0 -178
- package/dist/bin/cli/start/start.d.ts +0 -2
- package/dist/bin/cli/start/start.js +0 -27
- package/dist/bin/include/entry.d.ts +0 -2
- package/dist/bin/include/entry.js +0 -21
- package/dist/bin/plugins/XanixDocument/XanixDocument.d.ts +0 -2
- package/dist/bin/plugins/XanixDocument/XanixDocument.js +0 -50
- package/dist/bin/plugins/XanixDocument/index.d.ts +0 -2
- package/dist/bin/plugins/XanixDocument/index.js +0 -50
- package/dist/bin/plugins/XanixPageTransform-dep/index.d.ts +0 -2
- package/dist/bin/plugins/XanixPageTransform-dep/index.js +0 -62
- package/dist/bin/plugins/XanixPageTransform-dep/transformer.d.ts +0 -23
- package/dist/bin/plugins/XanixPageTransform-dep/transformer.js +0 -589
- package/dist/bin/plugins/XanixServerTransform.d.ts +0 -5
- package/dist/bin/plugins/XanixServerTransform.js +0 -207
- package/dist/bin/plugins/XanixUseServer.d.ts +0 -7
- package/dist/bin/plugins/XanixUseServer.js +0 -445
- package/dist/bin/plugins/plugins.d.ts +0 -8
- package/dist/bin/plugins/plugins.js +0 -31
- package/dist/components/Script.d.ts +0 -3
- package/dist/components/Script.js +0 -5
- package/dist/dev.d.ts +0 -1
- package/dist/dev.js +0 -25
- package/dist/react/createContext.d.ts +0 -3
- package/dist/react/createContext.js +0 -11
- package/dist/react/index.d.ts +0 -12
- package/dist/react/index.js +0 -3
- package/dist/server/express/Ruter.d.ts +0 -2
- package/dist/server/express/Ruter.js +0 -15
- package/dist/server/runtime/createServer.d.ts +0 -12
- package/dist/server/runtime/createServer.js +0 -62
- package/dist/server/runtime/index.d.ts +0 -3
- package/dist/server/runtime/index.js +0 -3
- package/dist/server/runtime/readManifest.d.ts +0 -14
- package/dist/server/runtime/readManifest.js +0 -9
- package/dist/server/runtime/xanixPage.d.ts +0 -11
- package/dist/server/runtime/xanixPage.js +0 -92
- /package/dist/bin/bundler/{plugins/XanixDocument/index.d.ts → client/plugins/XanixPage.d.ts} +0 -0
- /package/dist/bin/{cli/start/utils.d.ts → bundler/server/plugins/replacer/useServer.d.ts} +0 -0
- /package/dist/bin/{cli/start/utils.js → bundler/server/plugins/replacer/useServer.js} +0 -0
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
function importFinder(code, module) {
|
|
2
|
+
const esc = module.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
3
|
+
const from = `(?:"${esc}"|'${esc}')`;
|
|
4
|
+
const found = [];
|
|
5
|
+
// import a, { b as c }, * as ns from "module" (skips `import type ...`)
|
|
6
|
+
const importRe = new RegExp(`(?<![\\w$.])import(?![\\w$])(?!\\s+type\\s+[\\w$*{])\\s*([^;"']*?)\\s*from\\s*${from}`, "g");
|
|
7
|
+
for (const m of code.matchAll(importRe)) {
|
|
8
|
+
const clause = m[1];
|
|
9
|
+
const specifiers = [];
|
|
10
|
+
const namespace = /\*\s*as\s+([\w$]+)/.exec(clause)?.[1];
|
|
11
|
+
const named = /\{([^}]*)\}/.exec(clause)?.[1];
|
|
12
|
+
const def = clause
|
|
13
|
+
.replace(/\{[^}]*\}|\*\s*as\s+[\w$]+/g, "")
|
|
14
|
+
.replace(/,/g, "")
|
|
15
|
+
.trim();
|
|
16
|
+
if (/^[\w$]+$/.test(def))
|
|
17
|
+
specifiers.push({ local: def, imported: "default" });
|
|
18
|
+
for (const item of named?.split(",") ?? []) {
|
|
19
|
+
const s = item.trim();
|
|
20
|
+
if (!s || /^type\s+(?!as\s)/.test(s))
|
|
21
|
+
continue;
|
|
22
|
+
const [imported, local] = s.split(/\s+as\s+/).map((x) => x.trim());
|
|
23
|
+
specifiers.push({ local: local ?? imported, imported });
|
|
24
|
+
}
|
|
25
|
+
found.push({
|
|
26
|
+
index: m.index,
|
|
27
|
+
info: namespace ? { specifiers, namespace } : { specifiers },
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
// const a = require("module") / const { b, c: d } = require("module")
|
|
31
|
+
const requireRe = new RegExp(`(?<![\\w$.])(?:const|let|var)\\s+(?:([\\w$]+)|\\{([^}]*)\\})\\s*=\\s*require\\s*\\(\\s*${from}\\s*\\)(?![.(\\[])`, "g");
|
|
32
|
+
for (const m of code.matchAll(requireRe)) {
|
|
33
|
+
const specifiers = [];
|
|
34
|
+
if (m[1]) {
|
|
35
|
+
specifiers.push({ local: m[1], imported: "default" });
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
for (const item of m[2].split(",")) {
|
|
39
|
+
const s = item.trim().replace(/\s*=[\s\S]*$/, ""); // drop defaults
|
|
40
|
+
if (!s || s.startsWith("..."))
|
|
41
|
+
continue;
|
|
42
|
+
const [imported, local] = s.split(/\s*:\s*/).map((x) => x.trim());
|
|
43
|
+
specifiers.push({ local: local ?? imported, imported });
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
found.push({ index: m.index, info: { specifiers } });
|
|
47
|
+
}
|
|
48
|
+
return found.sort((a, b) => a.index - b.index).map((f) => f.info);
|
|
49
|
+
}
|
|
50
|
+
export default importFinder;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import findImports from "./findImports.js";
|
|
2
|
+
const ID = "[A-Za-z_$][\\w$]*";
|
|
3
|
+
function pageFinder(code) {
|
|
4
|
+
// default imports only:
|
|
5
|
+
// import Home from "./Home";
|
|
6
|
+
// import Layout, { Header } from "./Layout";
|
|
7
|
+
// import Components, * as UI from "./components";
|
|
8
|
+
const defaultImports = new Map();
|
|
9
|
+
for (const imp of findImports(code)) {
|
|
10
|
+
if (imp.default && !imp.typeOnly)
|
|
11
|
+
defaultImports.set(imp.default, imp.source);
|
|
12
|
+
}
|
|
13
|
+
// only: <identifier>.send(<Component />)
|
|
14
|
+
const sendRe = new RegExp(`(${ID}(?:\\??\\.${ID})*)\\??\\.send\\s*\\(\\s*(<([A-Z_$][\\w$]*)\\s*/>)\\s*\\)`, "g");
|
|
15
|
+
const results = [];
|
|
16
|
+
for (const m of code.matchAll(sendRe)) {
|
|
17
|
+
const source = defaultImports.get(m[3]);
|
|
18
|
+
if (!source)
|
|
19
|
+
continue;
|
|
20
|
+
results.push({
|
|
21
|
+
source,
|
|
22
|
+
identifier: m[1],
|
|
23
|
+
args: [m[2]],
|
|
24
|
+
start: m.index,
|
|
25
|
+
end: m.index + m[0].length,
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
return results;
|
|
29
|
+
}
|
|
30
|
+
export default pageFinder;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
const STRING = /"(?:\\[\s\S]|[^"\\])*"|'(?:\\[\s\S]|[^'\\])*'/;
|
|
2
|
+
// template literal: allows `${ ... }` with strings/templates inside (no nested braces),
|
|
3
|
+
// falls back to a plain backtick string
|
|
4
|
+
const TEMPLATE = /`(?:\\[\s\S]|\$\{(?:[^{}`]|`(?:\\[\s\S]|[^`\\])*`)*\}|[^`\\$]|\$(?!\{))*`|`(?:\\[\s\S]|[^`\\])*`/;
|
|
5
|
+
// regex literal: only where a regex can legally start (after an operator,
|
|
6
|
+
// opening bracket, keyword or start of file), and `/` allowed inside [...]
|
|
7
|
+
const REGEX = /(?<=(?:^|[(,=:[!&|?{};<>~^%*]|\b(?:return|typeof|case|void|delete|throw|yield|await|in|of))\s*)\/(?![/*])(?:\\.|\[(?:\\.|[^\]\\\r\n])*\]|[^/\\\r\n[])+\/[dgimsuvy]*/;
|
|
8
|
+
const COMMENT = /\/\*[\s\S]*?\*\/|\/\/[^\r\n]*/;
|
|
9
|
+
export const TOKENS = new RegExp([STRING, TEMPLATE, REGEX, COMMENT].map((r) => r.source).join("|"), "g");
|
|
10
|
+
function stripComments(code) {
|
|
11
|
+
return code.replace(TOKENS, (m) => m[0] === "/" && (m[1] === "/" || m[1] === "*")
|
|
12
|
+
? m.replace(/[^\r\n]/g, " ")
|
|
13
|
+
: m);
|
|
14
|
+
}
|
|
15
|
+
export default stripComments;
|
package/dist/bin/include/path.js
CHANGED
|
@@ -1,4 +1,18 @@
|
|
|
1
|
+
import os from "node:os";
|
|
1
2
|
import path from "node:path";
|
|
2
3
|
import { fileURLToPath } from "node:url";
|
|
3
4
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
4
|
-
|
|
5
|
+
const homeDir = os.homedir();
|
|
6
|
+
export const xanixHome = (() => {
|
|
7
|
+
if (process.platform === "win32") {
|
|
8
|
+
return path.join(process.env.LOCALAPPDATA || path.join(homeDir, "AppData", "Local"), "Xanix");
|
|
9
|
+
}
|
|
10
|
+
if (process.platform === "darwin") {
|
|
11
|
+
return path.join(homeDir, "Library", "Application Support", "Xanix");
|
|
12
|
+
}
|
|
13
|
+
return path.join(process.env.XDG_STATE_HOME || path.join(homeDir, ".local", "state"), "xanix");
|
|
14
|
+
})();
|
|
15
|
+
export const xanixProcesses = path.join(xanixHome, "processes");
|
|
16
|
+
export const xanixLogs = path.join(xanixHome, "logs");
|
|
17
|
+
export const xanixSaved = path.join(xanixHome, "saved");
|
|
18
|
+
export const framworkDir = path.resolve(__dirname, "../../../");
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
type SendFinderResult = {
|
|
2
2
|
file: string;
|
|
3
3
|
identifier: string;
|
|
4
|
+
args: string[];
|
|
5
|
+
start: number;
|
|
6
|
+
end: number;
|
|
4
7
|
};
|
|
5
|
-
declare function sendFinder(code: string): SendFinderResult[];
|
|
8
|
+
export declare function sendFinder(code: string): SendFinderResult[];
|
|
6
9
|
export default sendFinder;
|
|
@@ -1,40 +1,29 @@
|
|
|
1
|
-
function sendFinder(code) {
|
|
1
|
+
export function sendFinder(code) {
|
|
2
2
|
const results = [];
|
|
3
|
-
//
|
|
4
|
-
const imports = new Map();
|
|
5
|
-
const importRegex = /import\s+(?:(\w+)\s*,?\s*)?(?:\{\s*([^}]+)\s*\})?\s*from\s*["']([^"']+)["']/g;
|
|
6
|
-
for (const match of code.matchAll(importRegex)) {
|
|
7
|
-
const defaultName = match[1];
|
|
8
|
-
const named = match[2];
|
|
9
|
-
const file = match[3];
|
|
10
|
-
if (defaultName) {
|
|
11
|
-
imports.set(defaultName, file);
|
|
12
|
-
}
|
|
13
|
-
if (named) {
|
|
14
|
-
for (const item of named.split(",")) {
|
|
15
|
-
const [imported, local = imported] = item.trim().split(/\s+as\s+/);
|
|
16
|
-
imports.set(local, file);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
// import * as Pages from "./pages"
|
|
21
|
-
const namespaceRegex = /import\s+\*\s+as\s+(\w+)\s+from\s*["']([^"']+)["']/g;
|
|
22
|
-
for (const match of code.matchAll(namespaceRegex)) {
|
|
23
|
-
imports.set(match[1], match[2]);
|
|
24
|
-
}
|
|
25
|
-
// Find:
|
|
3
|
+
// Only store DEFAULT imports.
|
|
26
4
|
//
|
|
27
|
-
//
|
|
28
|
-
//
|
|
29
|
-
//
|
|
5
|
+
// import Home from "./Home";
|
|
6
|
+
// import Layout, { Header } from "./Layout";
|
|
7
|
+
// import Components, * as UI from "./components";
|
|
30
8
|
//
|
|
31
|
-
|
|
9
|
+
// Does NOT store:
|
|
10
|
+
// import { Layout } from "./Layout";
|
|
11
|
+
// import * as Pages from "./pages";
|
|
12
|
+
const defaultImports = new Map();
|
|
13
|
+
const defaultImportRegex = /import\s+([A-Za-z_$][\w$]*)\s*(?:,\s*(?:\{[^}]*\}|\*\s+as\s+[A-Za-z_$][\w$]*))?\s+from\s*["']([^"']+)["']/g;
|
|
14
|
+
for (const match of code.matchAll(defaultImportRegex)) {
|
|
15
|
+
const local = match[1];
|
|
16
|
+
const file = match[2];
|
|
17
|
+
defaultImports.set(local, file);
|
|
18
|
+
}
|
|
19
|
+
const sendRegex = /([A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*)*)\.send\s*\(/g;
|
|
32
20
|
let match;
|
|
33
21
|
while ((match = sendRegex.exec(code))) {
|
|
34
|
-
const identifier = `${match[1]}
|
|
35
|
-
const
|
|
22
|
+
const identifier = `${match[1]}`;
|
|
23
|
+
const start = match.index;
|
|
24
|
+
const argsStart = sendRegex.lastIndex;
|
|
36
25
|
let depth = 1;
|
|
37
|
-
let i =
|
|
26
|
+
let i = argsStart;
|
|
38
27
|
let quote = null;
|
|
39
28
|
for (; i < code.length; i++) {
|
|
40
29
|
const char = code[i];
|
|
@@ -61,40 +50,86 @@ function sendFinder(code) {
|
|
|
61
50
|
}
|
|
62
51
|
}
|
|
63
52
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
53
|
+
if (depth !== 0) {
|
|
54
|
+
break;
|
|
55
|
+
}
|
|
56
|
+
const end = i + 1;
|
|
57
|
+
const content = code.slice(argsStart, i);
|
|
58
|
+
const args = splitArguments(content);
|
|
59
|
+
const firstArg = args[0]?.trim();
|
|
60
|
+
if (!firstArg?.startsWith("<")) {
|
|
67
61
|
continue;
|
|
68
62
|
}
|
|
69
63
|
// <Home />
|
|
70
64
|
// <Home>
|
|
71
|
-
|
|
72
|
-
const jsxMatch = argument.match(/^<([A-Z_$][\w$]*(?:\.[A-Z_$][\w$]*)?)/);
|
|
65
|
+
const jsxMatch = firstArg.match(/^<([A-Z_$][\w$]*)/);
|
|
73
66
|
if (!jsxMatch) {
|
|
74
67
|
continue;
|
|
75
68
|
}
|
|
76
69
|
const component = jsxMatch[1];
|
|
77
|
-
|
|
78
|
-
if (!
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
70
|
+
const file = defaultImports.get(component);
|
|
71
|
+
if (!file) {
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
results.push({
|
|
75
|
+
file,
|
|
76
|
+
identifier,
|
|
77
|
+
args,
|
|
78
|
+
start,
|
|
79
|
+
end,
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
return results;
|
|
83
|
+
}
|
|
84
|
+
function splitArguments(code) {
|
|
85
|
+
const args = [];
|
|
86
|
+
let start = 0;
|
|
87
|
+
let paren = 0;
|
|
88
|
+
let brace = 0;
|
|
89
|
+
let bracket = 0;
|
|
90
|
+
let quote = null;
|
|
91
|
+
for (let i = 0; i < code.length; i++) {
|
|
92
|
+
const char = code[i];
|
|
93
|
+
if (quote) {
|
|
94
|
+
if (char === "\\") {
|
|
95
|
+
i++;
|
|
85
96
|
}
|
|
97
|
+
else if (char === quote) {
|
|
98
|
+
quote = null;
|
|
99
|
+
}
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
if (char === "'" || char === '"' || char === "`") {
|
|
103
|
+
quote = char;
|
|
86
104
|
continue;
|
|
87
105
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
if (
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
106
|
+
if (char === "(") {
|
|
107
|
+
paren++;
|
|
108
|
+
}
|
|
109
|
+
else if (char === ")") {
|
|
110
|
+
paren--;
|
|
111
|
+
}
|
|
112
|
+
else if (char === "{") {
|
|
113
|
+
brace++;
|
|
114
|
+
}
|
|
115
|
+
else if (char === "}") {
|
|
116
|
+
brace--;
|
|
117
|
+
}
|
|
118
|
+
else if (char === "[") {
|
|
119
|
+
bracket++;
|
|
120
|
+
}
|
|
121
|
+
else if (char === "]") {
|
|
122
|
+
bracket--;
|
|
123
|
+
}
|
|
124
|
+
else if (char === "," && paren === 0 && brace === 0 && bracket === 0) {
|
|
125
|
+
args.push(code.slice(start, i).trim());
|
|
126
|
+
start = i + 1;
|
|
96
127
|
}
|
|
97
128
|
}
|
|
98
|
-
|
|
129
|
+
const last = code.slice(start).trim();
|
|
130
|
+
if (last) {
|
|
131
|
+
args.push(last);
|
|
132
|
+
}
|
|
133
|
+
return args;
|
|
99
134
|
}
|
|
100
135
|
export default sendFinder;
|
package/dist/bin/index.js
CHANGED
|
File without changes
|
|
@@ -1,96 +1,51 @@
|
|
|
1
|
+
import { TOKENS } from "./stripComments.js";
|
|
2
|
+
const mask = (code) => code.replace(TOKENS, (m) => /^["'`]/.test(m)
|
|
3
|
+
? m[0] + m.slice(1, -1).replace(/[^\r\n]/g, " ") + m.at(-1)
|
|
4
|
+
: m.replace(/[^\r\n]/g, " "));
|
|
1
5
|
function callbackReplacer(code, name, replacer) {
|
|
6
|
+
const masked = mask(code);
|
|
2
7
|
const escaped = name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
3
|
-
const
|
|
8
|
+
const re = new RegExp(`(?<![\\w$.])${escaped}\\s*\\(`, "g");
|
|
4
9
|
let result = "";
|
|
5
10
|
let last = 0;
|
|
6
|
-
let
|
|
7
|
-
while ((
|
|
8
|
-
const start =
|
|
9
|
-
const
|
|
11
|
+
let m;
|
|
12
|
+
while ((m = re.exec(masked))) {
|
|
13
|
+
const start = m.index;
|
|
14
|
+
const cs = re.lastIndex;
|
|
15
|
+
// find the matching ")"
|
|
10
16
|
let depth = 1;
|
|
11
|
-
let i =
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const char = code[i];
|
|
15
|
-
if (quote) {
|
|
16
|
-
if (char === "\\") {
|
|
17
|
-
i++;
|
|
18
|
-
}
|
|
19
|
-
else if (char === quote) {
|
|
20
|
-
quote = null;
|
|
21
|
-
}
|
|
22
|
-
continue;
|
|
23
|
-
}
|
|
24
|
-
if (char === "'" || char === '"' || char === "`") {
|
|
25
|
-
quote = char;
|
|
26
|
-
continue;
|
|
27
|
-
}
|
|
28
|
-
if (char === "(") {
|
|
17
|
+
let i = cs;
|
|
18
|
+
for (; i < masked.length && depth; i++) {
|
|
19
|
+
if (masked[i] === "(")
|
|
29
20
|
depth++;
|
|
30
|
-
|
|
31
|
-
else if (char === ")") {
|
|
21
|
+
else if (masked[i] === ")")
|
|
32
22
|
depth--;
|
|
33
|
-
if (depth === 0) {
|
|
34
|
-
break;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
if (depth !== 0) {
|
|
39
|
-
break;
|
|
40
23
|
}
|
|
41
|
-
|
|
24
|
+
if (depth)
|
|
25
|
+
break; // unbalanced: leave the rest untouched
|
|
26
|
+
const end = i - 1;
|
|
27
|
+
// split top-level args
|
|
42
28
|
const args = [];
|
|
43
|
-
let argStart =
|
|
44
|
-
let
|
|
45
|
-
let
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
54
|
-
else if (char === quote) {
|
|
55
|
-
quote = null;
|
|
56
|
-
}
|
|
57
|
-
continue;
|
|
58
|
-
}
|
|
59
|
-
if (char === "'" || char === '"' || char === "`") {
|
|
60
|
-
quote = char;
|
|
61
|
-
continue;
|
|
62
|
-
}
|
|
63
|
-
if (char === "(")
|
|
64
|
-
paren++;
|
|
65
|
-
else if (char === ")")
|
|
66
|
-
paren--;
|
|
67
|
-
else if (char === "{")
|
|
68
|
-
brace++;
|
|
69
|
-
else if (char === "}")
|
|
70
|
-
brace--;
|
|
71
|
-
else if (char === "[")
|
|
72
|
-
bracket++;
|
|
73
|
-
else if (char === "]")
|
|
74
|
-
bracket--;
|
|
75
|
-
if (char === "," && paren === 0 && brace === 0 && bracket === 0) {
|
|
76
|
-
args.push(content.slice(argStart, j).trim());
|
|
29
|
+
let argStart = cs;
|
|
30
|
+
let d = 0;
|
|
31
|
+
for (let j = cs; j < end; j++) {
|
|
32
|
+
const c = masked[j];
|
|
33
|
+
if (c === "(" || c === "[" || c === "{")
|
|
34
|
+
d++;
|
|
35
|
+
else if (c === ")" || c === "]" || c === "}")
|
|
36
|
+
d--;
|
|
37
|
+
else if (c === "," && d === 0) {
|
|
38
|
+
args.push(code.slice(argStart, j).trim());
|
|
77
39
|
argStart = j + 1;
|
|
78
40
|
}
|
|
79
41
|
}
|
|
80
|
-
const
|
|
81
|
-
if (
|
|
82
|
-
args.push(
|
|
83
|
-
}
|
|
42
|
+
const tail = code.slice(argStart, end).trim();
|
|
43
|
+
if (tail)
|
|
44
|
+
args.push(tail);
|
|
84
45
|
result += code.slice(last, start);
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
}
|
|
89
|
-
else {
|
|
90
|
-
result += code.slice(start, i + 1);
|
|
91
|
-
}
|
|
92
|
-
last = i + 1;
|
|
93
|
-
regex.lastIndex = i + 1;
|
|
46
|
+
const out = replacer(args);
|
|
47
|
+
result += out !== undefined ? out : code.slice(start, end + 1);
|
|
48
|
+
last = re.lastIndex = end + 1;
|
|
94
49
|
}
|
|
95
50
|
return result + code.slice(last);
|
|
96
51
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export type ImportSpecifier = {
|
|
2
|
+
imported: string;
|
|
3
|
+
local: string;
|
|
4
|
+
typeOnly: boolean;
|
|
5
|
+
};
|
|
6
|
+
export type ImportRecord = {
|
|
7
|
+
source: string;
|
|
8
|
+
default?: string;
|
|
9
|
+
namespace?: string;
|
|
10
|
+
named: ImportSpecifier[];
|
|
11
|
+
typeOnly: boolean;
|
|
12
|
+
start: number;
|
|
13
|
+
end: number;
|
|
14
|
+
};
|
|
15
|
+
declare function findImports(code: string): ImportRecord[];
|
|
16
|
+
export default findImports;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { TOKENS } from "./stripComments.js";
|
|
2
|
+
// Blank comments, regex literals and string/template contents (length preserved,
|
|
3
|
+
// quote characters kept) so imports inside them are never matched.
|
|
4
|
+
const mask = (code) => code.replace(TOKENS, (m) => /^["'`]/.test(m)
|
|
5
|
+
? m[0] + m.slice(1, -1).replace(/[^\r\n]/g, " ") + m.at(-1)
|
|
6
|
+
: m.replace(/[^\r\n]/g, " "));
|
|
7
|
+
const IMPORT_RE = /(?<![\w$.])(?<head>import(?![\w$])\s*)(?<pre>(?:(?<type>type\s+(?!from\b)(?=[\w$*{]))?(?<clause>[^;"'`]*?)\s*from\s*)?)(?<q>["'])(?<src>[^"']+)\k<q>(?:\s*(?:with|assert)\s*\{[^}]*\})?;?/g;
|
|
8
|
+
function findImports(code) {
|
|
9
|
+
const records = [];
|
|
10
|
+
for (const m of mask(code).matchAll(IMPORT_RE)) {
|
|
11
|
+
const g = m.groups;
|
|
12
|
+
const srcStart = m.index + g.head.length + g.pre.length + 1;
|
|
13
|
+
const clause = g.clause ?? "";
|
|
14
|
+
const record = {
|
|
15
|
+
source: code.slice(srcStart, srcStart + g.src.length),
|
|
16
|
+
named: [],
|
|
17
|
+
typeOnly: !!g.type,
|
|
18
|
+
start: m.index,
|
|
19
|
+
end: m.index + m[0].length,
|
|
20
|
+
};
|
|
21
|
+
const namespace = /\*\s*as\s+([\w$]+)/.exec(clause)?.[1];
|
|
22
|
+
if (namespace)
|
|
23
|
+
record.namespace = namespace;
|
|
24
|
+
const named = /\{([^}]*)\}/.exec(clause)?.[1];
|
|
25
|
+
for (const item of named?.split(",") ?? []) {
|
|
26
|
+
let s = item.trim();
|
|
27
|
+
if (!s)
|
|
28
|
+
continue;
|
|
29
|
+
const typeOnly = /^type\s+(?!as\s)/.test(s);
|
|
30
|
+
if (typeOnly)
|
|
31
|
+
s = s.replace(/^type\s+/, "");
|
|
32
|
+
const [imported, local] = s.split(/\s+as\s+/).map((x) => x.trim());
|
|
33
|
+
record.named.push({ imported, local: local ?? imported, typeOnly });
|
|
34
|
+
}
|
|
35
|
+
const def = clause
|
|
36
|
+
.replace(/\{[^}]*\}|\*\s*as\s+[\w$]+/g, "")
|
|
37
|
+
.replace(/,/g, "")
|
|
38
|
+
.trim();
|
|
39
|
+
if (/^[\w$]+$/.test(def))
|
|
40
|
+
record.default = def;
|
|
41
|
+
records.push(record);
|
|
42
|
+
}
|
|
43
|
+
return records;
|
|
44
|
+
}
|
|
45
|
+
export default findImports;
|
|
@@ -1,69 +1,50 @@
|
|
|
1
1
|
function importFinder(code, module) {
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
for (const
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
};
|
|
2
|
+
const esc = module.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
3
|
+
const from = `(?:"${esc}"|'${esc}')`;
|
|
4
|
+
const found = [];
|
|
5
|
+
// import a, { b as c }, * as ns from "module" (skips `import type ...`)
|
|
6
|
+
const importRe = new RegExp(`(?<![\\w$.])import(?![\\w$])(?!\\s+type\\s+[\\w$*{])\\s*([^;"']*?)\\s*from\\s*${from}`, "g");
|
|
7
|
+
for (const m of code.matchAll(importRe)) {
|
|
8
|
+
const clause = m[1];
|
|
9
|
+
const specifiers = [];
|
|
10
|
+
const namespace = /\*\s*as\s+([\w$]+)/.exec(clause)?.[1];
|
|
11
|
+
const named = /\{([^}]*)\}/.exec(clause)?.[1];
|
|
12
|
+
const def = clause
|
|
13
|
+
.replace(/\{[^}]*\}|\*\s*as\s+[\w$]+/g, "")
|
|
14
|
+
.replace(/,/g, "")
|
|
15
|
+
.trim();
|
|
16
|
+
if (/^[\w$]+$/.test(def))
|
|
17
|
+
specifiers.push({ local: def, imported: "default" });
|
|
18
|
+
for (const item of named?.split(",") ?? []) {
|
|
19
|
+
const s = item.trim();
|
|
20
|
+
if (!s || /^type\s+(?!as\s)/.test(s))
|
|
21
|
+
continue;
|
|
22
|
+
const [imported, local] = s.split(/\s+as\s+/).map((x) => x.trim());
|
|
23
|
+
specifiers.push({ local: local ?? imported, imported });
|
|
24
|
+
}
|
|
25
|
+
found.push({
|
|
26
|
+
index: m.index,
|
|
27
|
+
info: namespace ? { specifiers, namespace } : { specifiers },
|
|
18
28
|
});
|
|
19
|
-
result.push({ specifiers });
|
|
20
29
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
.
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
result.push({
|
|
39
|
-
specifiers: [
|
|
40
|
-
{
|
|
41
|
-
local: match[1],
|
|
42
|
-
imported: "default",
|
|
43
|
-
},
|
|
44
|
-
],
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
// import * as foo from "module"
|
|
48
|
-
const namespaceImport = new RegExp(`import\\s*\\*\\s*as\\s*([\\w$]+)\\s*from\\s*["']${escaped}["']`, "g");
|
|
49
|
-
for (const match of code.matchAll(namespaceImport)) {
|
|
50
|
-
result.push({
|
|
51
|
-
specifiers: [],
|
|
52
|
-
namespace: match[1],
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
// const foo = require("module")
|
|
56
|
-
const requireImport = new RegExp(`(?:const|let|var)\\s+([\\w$]+)\\s*=\\s*require\\s*\\(\\s*["']${escaped}["']\\s*\\)`, "g");
|
|
57
|
-
for (const match of code.matchAll(requireImport)) {
|
|
58
|
-
result.push({
|
|
59
|
-
specifiers: [
|
|
60
|
-
{
|
|
61
|
-
local: match[1],
|
|
62
|
-
imported: "default",
|
|
63
|
-
},
|
|
64
|
-
],
|
|
65
|
-
});
|
|
30
|
+
// const a = require("module") / const { b, c: d } = require("module")
|
|
31
|
+
const requireRe = new RegExp(`(?<![\\w$.])(?:const|let|var)\\s+(?:([\\w$]+)|\\{([^}]*)\\})\\s*=\\s*require\\s*\\(\\s*${from}\\s*\\)(?![.(\\[])`, "g");
|
|
32
|
+
for (const m of code.matchAll(requireRe)) {
|
|
33
|
+
const specifiers = [];
|
|
34
|
+
if (m[1]) {
|
|
35
|
+
specifiers.push({ local: m[1], imported: "default" });
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
for (const item of m[2].split(",")) {
|
|
39
|
+
const s = item.trim().replace(/\s*=[\s\S]*$/, ""); // drop defaults
|
|
40
|
+
if (!s || s.startsWith("..."))
|
|
41
|
+
continue;
|
|
42
|
+
const [imported, local] = s.split(/\s*:\s*/).map((x) => x.trim());
|
|
43
|
+
specifiers.push({ local: local ?? imported, imported });
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
found.push({ index: m.index, info: { specifiers } });
|
|
66
47
|
}
|
|
67
|
-
return
|
|
48
|
+
return found.sort((a, b) => a.index - b.index).map((f) => f.info);
|
|
68
49
|
}
|
|
69
50
|
export default importFinder;
|