@startracex/node-resolve 0.0.0 → 0.2.0
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/README.md +10 -29
- package/index.cjs +2 -0
- package/index.cjs.map +1 -0
- package/index.d.ts +2 -4
- package/index.d.ts.map +1 -1
- package/index.mjs +2 -0
- package/index.mjs.map +1 -0
- package/main.wasm +0 -0
- package/package.json +9 -17
- package/shared.cjs +2 -0
- package/shared.cjs.map +1 -0
- package/shared.d.ts +27 -0
- package/shared.d.ts.map +1 -0
- package/shared.mjs +2 -0
- package/shared.mjs.map +1 -0
- package/wasm_exec.cjs +3 -0
- package/wasm_exec.cjs.map +1 -0
- package/wasm_exec.mjs +3 -0
- package/wasm_exec.mjs.map +1 -0
- package/LICENSE +0 -21
- package/index.js +0 -3
- package/index.ts +0 -3
- package/module-resolver.d.ts +0 -34
- package/module-resolver.d.ts.map +0 -1
- package/module-resolver.js +0 -141
- package/module-resolver.ts +0 -186
- package/specifier.d.ts +0 -14
- package/specifier.d.ts.map +0 -1
- package/specifier.js +0 -28
- package/specifier.ts +0 -40
- package/subpath-resolver.d.ts +0 -18
- package/subpath-resolver.d.ts.map +0 -1
- package/subpath-resolver.js +0 -114
- package/subpath-resolver.ts +0 -150
package/README.md
CHANGED
|
@@ -1,35 +1,16 @@
|
|
|
1
1
|
# node-resolve
|
|
2
2
|
|
|
3
|
-
```
|
|
4
|
-
import {
|
|
5
|
-
import fs from "node:fs";
|
|
6
|
-
import path from "node:path";
|
|
3
|
+
```js
|
|
4
|
+
import { createResolve } from "@startracex/node-resolve";
|
|
7
5
|
|
|
8
|
-
const
|
|
9
|
-
extensions: [".js"],
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
fs: fs,
|
|
6
|
+
const resolve = await createResolve({
|
|
7
|
+
extensions: [".js", ".ts"],
|
|
8
|
+
extensionMap: {
|
|
9
|
+
".js": [".ts", ".js"],
|
|
10
|
+
},
|
|
14
11
|
});
|
|
15
12
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
```go
|
|
20
|
-
import (
|
|
21
|
-
"strings"
|
|
22
|
-
resolve "github.com/startracex/node-resolve"
|
|
23
|
-
)
|
|
24
|
-
|
|
25
|
-
func main() {
|
|
26
|
-
resolver := resolve.NewModuleResolver(&resolve.ResolverConfig{
|
|
27
|
-
Extensions: []string{".js"},
|
|
28
|
-
IsCoreModule: func(s string) bool {
|
|
29
|
-
return strings.HasPrefix(s, "node:")
|
|
30
|
-
},
|
|
31
|
-
MainFields: []string{"main"},
|
|
32
|
-
})
|
|
33
|
-
resolved := resolver.Resolve("@scope/pkg", "/dir/of/resolver") // /dir/node_modules/@scope/pkg/index.js
|
|
34
|
-
}
|
|
13
|
+
let resolved, cwd = process.cwd()
|
|
14
|
+
resolved = resolve("./file.js", cwd); // file.ts
|
|
15
|
+
resolved = resolve("typescript", cwd); // node_modules/typescript/lib/typescript.js
|
|
35
16
|
```
|
package/index.cjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var e=require(`node:path`),t=require(`node:fs`),n=require(`./shared.cjs`),r=require(`./wasm_exec.cjs`);require(`node:module`);const i=new r.Go;let a=!1;const o=async()=>{if(a)return;let n=e.join(__dirname,`main.wasm`),r=t.readFileSync(n),o=await WebAssembly.instantiate(r,i.importObject);i.run(o.instance),a=!0},s=async e=>(await o(),globalThis[`@startracex/node-resolve`](n.normalizeOptions(e)));exports.createResolve=s;
|
|
2
|
+
//# sourceMappingURL=index.cjs.map
|
package/index.cjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../src/index.ts"],"sourcesContent":["import { dirname, join } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport { readFileSync } from \"node:fs\";\nimport { type Options, normalizeOptions } from \"./shared.js\";\nimport { Go } from \"./wasm_exec.js\";\n\nconst go = new Go();\nlet loaded = false;\nconst init = async () => {\n if (loaded) {\n return;\n }\n const wasmPath = join(dirname(fileURLToPath(import.meta.url)), \"main.wasm\");\n const buffer = readFileSync(wasmPath);\n const result = await WebAssembly.instantiate(buffer, go.importObject);\n go.run(result.instance);\n loaded = true;\n};\n\nexport const createResolve = async (\n options?: Options,\n): Promise<(req: string, dir: string) => string> => {\n await init();\n\n return globalThis[\"@startracex/node-resolve\"](normalizeOptions(options));\n};\n"],"names":["go","Go","loaded","init","wasmPath","join","buffer","readFileSync","result","createResolve","normalizeOptions","options"],"mappings":"2IAMA,MAAMA,EAAK,IAAIC,EAAAA,GACf,IAAIC,EAAS,GACb,MAAMC,EAAO,SAAY,CACvB,GAAID,EACF,OAEF,IAAME,EAAWC,EAAAA,KAAK,UAAW,aAC3BC,EAASC,EAAAA,aAAaH,GACtBI,EAAS,MAAM,YAAY,YAAYF,EAAQN,EAAG,cACxDA,EAAG,IAAIQ,EAAO,UACd,EAAS,IAGEC,EAAgB,KAC3B,KAEA,MAAMN,IAEC,WAAW,4BAA4BO,EAAAA,iBAAiBC"}
|
package/index.d.ts
CHANGED
|
@@ -1,4 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
3
|
-
export * from "./subpath-resolver.js";
|
|
4
|
-
//# sourceMappingURL=index.d.ts.map
|
|
1
|
+
import { type Options } from "./shared.js";
|
|
2
|
+
export declare const createResolve: (options?: Options) => Promise<(req: string, dir: string) => string>;
|
package/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"
|
|
1
|
+
{"mappings":"AAGA,cAAc,eAAiC;AAgB/C,OAAO,cAAM,gBACX,UAAU,YACT,SAAS,aAAa","names":[],"sources":["../../src/index.ts"],"sourcesContent":["import { dirname, join } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport { readFileSync } from \"node:fs\";\nimport { type Options, normalizeOptions } from \"./shared.js\";\nimport { Go } from \"./wasm_exec.js\";\n\nconst go = new Go();\nlet loaded = false;\nconst init = async () => {\n if (loaded) {\n return;\n }\n const wasmPath = join(dirname(fileURLToPath(import.meta.url)), \"main.wasm\");\n const buffer = readFileSync(wasmPath);\n const result = await WebAssembly.instantiate(buffer, go.importObject);\n go.run(result.instance);\n loaded = true;\n};\n\nexport const createResolve = async (\n options?: Options,\n): Promise<(req: string, dir: string) => string> => {\n await init();\n\n return globalThis[\"@startracex/node-resolve\"](normalizeOptions(options));\n};\n"],"version":3,"file":"index.d.ts"}
|
package/index.mjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{join as e,dirname as t}from"node:path";import{fileURLToPath as n}from"node:url";import{readFileSync as r}from"node:fs";import{normalizeOptions as i}from"./shared.mjs";import{Go as a}from"./wasm_exec.mjs";import"node:module";const o=new a;let s=!1;const c=async()=>{if(s)return;let i=e(t(n(import.meta.url)),`main.wasm`),a=r(i),c=await WebAssembly.instantiate(a,o.importObject);o.run(c.instance),s=!0},l=async e=>(await c(),globalThis[`@startracex/node-resolve`](i(e)));export{l as createResolve};
|
|
2
|
+
//# sourceMappingURL=index.mjs.map
|
package/index.mjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../src/index.ts"],"sourcesContent":["import { dirname, join } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport { readFileSync } from \"node:fs\";\nimport { type Options, normalizeOptions } from \"./shared.js\";\nimport { Go } from \"./wasm_exec.js\";\n\nconst go = new Go();\nlet loaded = false;\nconst init = async () => {\n if (loaded) {\n return;\n }\n const wasmPath = join(dirname(fileURLToPath(import.meta.url)), \"main.wasm\");\n const buffer = readFileSync(wasmPath);\n const result = await WebAssembly.instantiate(buffer, go.importObject);\n go.run(result.instance);\n loaded = true;\n};\n\nexport const createResolve = async (\n options?: Options,\n): Promise<(req: string, dir: string) => string> => {\n await init();\n\n return globalThis[\"@startracex/node-resolve\"](normalizeOptions(options));\n};\n"],"names":["go","Go","loaded","init","wasmPath","join","dirname","fileURLToPath","buffer","readFileSync","result","createResolve","normalizeOptions","options"],"mappings":"uOAMA,MAAMA,EAAK,IAAIC,EACf,IAAIC,EAAS,GACb,MAAMC,EAAO,SAAY,CACvB,GAAID,EACF,OAEF,IAAME,EAAWC,EAAKC,EAAQC,EAAc,OAAO,KAAK,MAAO,aACzDC,EAASC,EAAaL,GACtBM,EAAS,MAAM,YAAY,YAAYF,EAAQR,EAAG,cACxDA,EAAG,IAAIU,EAAO,UACd,EAAS,IAGEC,EAAgB,KAC3B,KAEA,MAAMR,IAEC,WAAW,4BAA4BS,EAAiBC"}
|
package/main.wasm
ADDED
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,19 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@startracex/node-resolve",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Node resolve algorithm",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
"devDependencies": {
|
|
14
|
-
"@startracex/dev-config": "^0.2.2",
|
|
15
|
-
"dprint": "^0.50.0",
|
|
16
|
-
"typescript": "^5.8.3"
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"types": "./index.d.ts",
|
|
9
|
+
"import": "./index.mjs",
|
|
10
|
+
"require": "./index.cjs"
|
|
11
|
+
},
|
|
12
|
+
"./*": "./*"
|
|
17
13
|
},
|
|
18
14
|
"keywords": [
|
|
19
15
|
"node",
|
|
@@ -26,9 +22,5 @@
|
|
|
26
22
|
"repository": {
|
|
27
23
|
"type": "git",
|
|
28
24
|
"url": "git+https://github.com/startracex/node-resolve.git"
|
|
29
|
-
}
|
|
30
|
-
"files": [
|
|
31
|
-
"*.{js,ts}+(|.map)"
|
|
32
|
-
],
|
|
33
|
-
"packageManager": "pnpm@10.11.0"
|
|
25
|
+
}
|
|
34
26
|
}
|
package/shared.cjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var e=require(`node:fs`),t=require(`node:path`),n=require(`node:module`);const r=e=>e.startsWith(`node:`),i=new Set(n.builtinModules.filter(e=>!r(e)).map(e=>{let t=e.indexOf(`/`);return t===-1?e:e.substring(0,t)})),a=e=>r(e)||i.has(e),o={stat:t=>{try{let n=e.statSync(t);return{exists:!0,isDir:n.isDirectory(),size:n.size,mtime:n.mtimeMs}}catch{return{exists:!1,isDir:!1,size:0,mtime:0}}},readFile:t=>e.readFileSync(t).toString(`base64`)},s={dir:t.dirname,join:t.join},c=`default`,l=({extensions:e=[`.js`],extensionMap:t={},mainFields:n=[`main`],conditions:r=[c],indexName:i=`index`,modulesDirectoryName:l=`node_modules`,manifestFileName:u=`package.json`,isCoreModule:d=a,path:f=s,fs:p=o}={})=>(r.includes(c)||r.push(c),{extensions:e,extensionMap:t,mainFields:n,conditions:r,indexName:i,modulesDirectoryName:l,manifestFileName:u,path:f,fs:p,isCoreModule:d});exports.normalizeOptions=l;
|
|
2
|
+
//# sourceMappingURL=shared.cjs.map
|
package/shared.cjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared.cjs","sources":["../src/shared.ts"],"sourcesContent":["import { readFileSync, statSync } from \"node:fs\";\nimport { dirname as dir, join } from \"node:path\";\nimport { builtinModules } from \"node:module\";\n\nconst isNodeProto = (id: string) => id.startsWith(\"node:\");\n\nconst coreModuleSet = new Set(\n builtinModules\n .filter((id) => !isNodeProto(id))\n .map((id) => {\n const index = id.indexOf(\"/\");\n return index === -1 ? id : id.substring(0, index);\n }),\n);\n\nconst _isCoreModule = (id: string) => isNodeProto(id) || coreModuleSet.has(id);\n\nconst _fs: {\n stat: (path: any) => {\n exists: boolean;\n isDir: boolean;\n size: number;\n mtime: number;\n };\n readFile: (path: any) => string;\n} = {\n stat: (path) => {\n try {\n const info = statSync(path);\n return {\n exists: true,\n isDir: info.isDirectory(),\n size: info.size,\n mtime: info.mtimeMs,\n };\n } catch {\n return {\n exists: false,\n isDir: false,\n size: 0,\n mtime: 0,\n };\n }\n },\n readFile: (path) => {\n return readFileSync(path).toString(\"base64\");\n },\n};\n\nconst _path: {\n dir: (path: string) => string;\n join: (...paths: string[]) => string;\n} = {\n dir,\n join,\n};\n\nconst _default = \"default\";\n\nexport type Options = {\n extensions?: string[];\n extensionMap?: {};\n mainFields?: string[];\n conditions?: string[];\n indexName?: string;\n modulesDirectoryName?: string;\n manifestFileName?: string;\n isCoreModule?: (id: any) => boolean;\n path?: typeof _path;\n fs?: typeof _fs;\n};\n\nexport const normalizeOptions = ({\n extensions = [\".js\"],\n extensionMap = {},\n mainFields = [\"main\"],\n conditions = [_default],\n indexName = \"index\",\n modulesDirectoryName = \"node_modules\",\n manifestFileName = \"package.json\",\n isCoreModule = _isCoreModule,\n path = _path,\n fs = _fs,\n}: Options = {}): Options => {\n if (!conditions.includes(_default)) {\n conditions.push(_default);\n }\n return {\n extensions,\n extensionMap,\n mainFields,\n conditions,\n indexName,\n modulesDirectoryName,\n manifestFileName,\n path,\n fs,\n isCoreModule,\n };\n};\n"],"names":["isNodeProto","id","coreModuleSet","builtinModules","index","_isCoreModule","_fs: {\n stat: (path: any) => {\n exists: boolean;\n isDir: boolean;\n size: number;\n mtime: number;\n };\n readFile: (path: any) => string;\n}","info","statSync","path","readFileSync","_path: {\n dir: (path: string) => string;\n join: (...paths: string[]) => string;\n}","dir","join","_default","normalizeOptions","_path","_fs","conditions"],"mappings":"sFAIA,MAAMA,EAAe,GAAeC,EAAG,WAAW,SAE5CC,EAAgB,IAAI,IACxBC,EAAAA,eACG,OAAQ,GAAO,CAACH,EAAYC,IAC5B,IAAK,GAAO,CACX,IAAMG,EAAQH,EAAG,QAAQ,KACzB,OAAOG,IAAU,GAAKH,EAAKA,EAAG,UAAU,EAAGG,MAI3CC,EAAiB,GAAeL,EAAYC,IAAOC,EAAc,IAAID,GAErEK,EAQF,CACF,KAAO,GAAS,CACd,GAAI,CACF,IAAMC,EAAOC,EAAAA,SAASC,GACtB,MAAO,CACL,OAAQ,GACR,MAAOF,EAAK,cACZ,KAAMA,EAAK,KACX,MAAOA,EAAK,cAER,CACN,MAAO,CACL,OAAQ,GACR,MAAO,GACP,KAAM,EACN,MAAO,KAIb,SAAW,GACFG,eAAaD,GAAM,SAAS,WAIjCE,EAGF,CACF,IAAAC,EAAAA,QACA,KAAAC,EAAAA,MAGIC,EAAW,UAeJC,GAAoB,CAC/B,aAAa,CAAC,OACd,eAAe,GACf,aAAa,CAAC,QACd,aAAa,CAACD,GACd,YAAY,QACZ,uBAAuB,eACvB,mBAAmB,eACnB,eAAeT,EACf,OAAOW,EACP,KAAKC,GACM,MACNC,EAAW,SAASJ,IACvBI,EAAW,KAAKJ,GAEX,CACL,aACA,eACA,aACA,aACA,YACA,uBACA,mBACA,OACA,KACA"}
|
package/shared.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
declare const _fs: {
|
|
2
|
+
stat: (path: any) => {
|
|
3
|
+
exists: boolean;
|
|
4
|
+
isDir: boolean;
|
|
5
|
+
size: number;
|
|
6
|
+
mtime: number;
|
|
7
|
+
};
|
|
8
|
+
readFile: (path: any) => string;
|
|
9
|
+
};
|
|
10
|
+
declare const _path: {
|
|
11
|
+
dir: (path: string) => string;
|
|
12
|
+
join: (...paths: string[]) => string;
|
|
13
|
+
};
|
|
14
|
+
export type Options = {
|
|
15
|
+
extensions?: string[];
|
|
16
|
+
extensionMap?: {};
|
|
17
|
+
mainFields?: string[];
|
|
18
|
+
conditions?: string[];
|
|
19
|
+
indexName?: string;
|
|
20
|
+
modulesDirectoryName?: string;
|
|
21
|
+
manifestFileName?: string;
|
|
22
|
+
isCoreModule?: (id: any) => boolean;
|
|
23
|
+
path?: typeof _path;
|
|
24
|
+
fs?: typeof _fs;
|
|
25
|
+
};
|
|
26
|
+
export declare const normalizeOptions: ({ extensions, extensionMap, mainFields, conditions, indexName, modulesDirectoryName, manifestFileName, isCoreModule, path, fs }?: Options) => Options;
|
|
27
|
+
export {};
|
package/shared.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":"AAiBA,cAAMA,KAAK;CACT,OAAO,cAAc;EACnB;EACA;EACA;EACA;;CAEF,WAAW;;AAyBb,cAAMC,OAAO;CACX,MAAM;CACN,OAAO,GAAG;;AAQZ,YAAY,UAAU;CACpB;CACA,eAAe;CACf;CACA;CACA;CACA;CACA;CACA,gBAAgB;CAChB,cAAc;CACd,YAAY;;AAGd,OAAO,cAAM,mBAAoB,EAC/B,YACA,cACA,YACA,YACA,WACA,sBACA,kBACA,cACA,MACA,OACC,YAAe","names":["_fs: {\n stat: (path: any) => {\n exists: boolean;\n isDir: boolean;\n size: number;\n mtime: number;\n };\n readFile: (path: any) => string;\n}","_path: {\n dir: (path: string) => string;\n join: (...paths: string[]) => string;\n}"],"sources":["../../src/shared.ts"],"sourcesContent":["import { readFileSync, statSync } from \"node:fs\";\nimport { dirname as dir, join } from \"node:path\";\nimport { builtinModules } from \"node:module\";\n\nconst isNodeProto = (id: string) => id.startsWith(\"node:\");\n\nconst coreModuleSet = new Set(\n builtinModules\n .filter((id) => !isNodeProto(id))\n .map((id) => {\n const index = id.indexOf(\"/\");\n return index === -1 ? id : id.substring(0, index);\n }),\n);\n\nconst _isCoreModule = (id: string) => isNodeProto(id) || coreModuleSet.has(id);\n\nconst _fs: {\n stat: (path: any) => {\n exists: boolean;\n isDir: boolean;\n size: number;\n mtime: number;\n };\n readFile: (path: any) => string;\n} = {\n stat: (path) => {\n try {\n const info = statSync(path);\n return {\n exists: true,\n isDir: info.isDirectory(),\n size: info.size,\n mtime: info.mtimeMs,\n };\n } catch {\n return {\n exists: false,\n isDir: false,\n size: 0,\n mtime: 0,\n };\n }\n },\n readFile: (path) => {\n return readFileSync(path).toString(\"base64\");\n },\n};\n\nconst _path: {\n dir: (path: string) => string;\n join: (...paths: string[]) => string;\n} = {\n dir,\n join,\n};\n\nconst _default = \"default\";\n\nexport type Options = {\n extensions?: string[];\n extensionMap?: {};\n mainFields?: string[];\n conditions?: string[];\n indexName?: string;\n modulesDirectoryName?: string;\n manifestFileName?: string;\n isCoreModule?: (id: any) => boolean;\n path?: typeof _path;\n fs?: typeof _fs;\n};\n\nexport const normalizeOptions = ({\n extensions = [\".js\"],\n extensionMap = {},\n mainFields = [\"main\"],\n conditions = [_default],\n indexName = \"index\",\n modulesDirectoryName = \"node_modules\",\n manifestFileName = \"package.json\",\n isCoreModule = _isCoreModule,\n path = _path,\n fs = _fs,\n}: Options = {}): Options => {\n if (!conditions.includes(_default)) {\n conditions.push(_default);\n }\n return {\n extensions,\n extensionMap,\n mainFields,\n conditions,\n indexName,\n modulesDirectoryName,\n manifestFileName,\n path,\n fs,\n isCoreModule,\n };\n};\n"],"version":3,"file":"shared.d.ts"}
|
package/shared.mjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{readFileSync as e,statSync as t}from"node:fs";import{join as n,dirname as r}from"node:path";import{builtinModules as i}from"node:module";const a=e=>e.startsWith(`node:`),o=new Set(i.filter(e=>!a(e)).map(e=>{let t=e.indexOf(`/`);return t===-1?e:e.substring(0,t)})),s=e=>a(e)||o.has(e),c={stat:e=>{try{let n=t(e);return{exists:!0,isDir:n.isDirectory(),size:n.size,mtime:n.mtimeMs}}catch{return{exists:!1,isDir:!1,size:0,mtime:0}}},readFile:t=>e(t).toString(`base64`)},l={dir:r,join:n},u=`default`,d=({extensions:e=[`.js`],extensionMap:t={},mainFields:n=[`main`],conditions:r=[u],indexName:i=`index`,modulesDirectoryName:a=`node_modules`,manifestFileName:o=`package.json`,isCoreModule:d=s,path:f=l,fs:p=c}={})=>(r.includes(u)||r.push(u),{extensions:e,extensionMap:t,mainFields:n,conditions:r,indexName:i,modulesDirectoryName:a,manifestFileName:o,path:f,fs:p,isCoreModule:d});export{d as normalizeOptions};
|
|
2
|
+
//# sourceMappingURL=shared.mjs.map
|
package/shared.mjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared.mjs","sources":["../src/shared.ts"],"sourcesContent":["import { readFileSync, statSync } from \"node:fs\";\nimport { dirname as dir, join } from \"node:path\";\nimport { builtinModules } from \"node:module\";\n\nconst isNodeProto = (id: string) => id.startsWith(\"node:\");\n\nconst coreModuleSet = new Set(\n builtinModules\n .filter((id) => !isNodeProto(id))\n .map((id) => {\n const index = id.indexOf(\"/\");\n return index === -1 ? id : id.substring(0, index);\n }),\n);\n\nconst _isCoreModule = (id: string) => isNodeProto(id) || coreModuleSet.has(id);\n\nconst _fs: {\n stat: (path: any) => {\n exists: boolean;\n isDir: boolean;\n size: number;\n mtime: number;\n };\n readFile: (path: any) => string;\n} = {\n stat: (path) => {\n try {\n const info = statSync(path);\n return {\n exists: true,\n isDir: info.isDirectory(),\n size: info.size,\n mtime: info.mtimeMs,\n };\n } catch {\n return {\n exists: false,\n isDir: false,\n size: 0,\n mtime: 0,\n };\n }\n },\n readFile: (path) => {\n return readFileSync(path).toString(\"base64\");\n },\n};\n\nconst _path: {\n dir: (path: string) => string;\n join: (...paths: string[]) => string;\n} = {\n dir,\n join,\n};\n\nconst _default = \"default\";\n\nexport type Options = {\n extensions?: string[];\n extensionMap?: {};\n mainFields?: string[];\n conditions?: string[];\n indexName?: string;\n modulesDirectoryName?: string;\n manifestFileName?: string;\n isCoreModule?: (id: any) => boolean;\n path?: typeof _path;\n fs?: typeof _fs;\n};\n\nexport const normalizeOptions = ({\n extensions = [\".js\"],\n extensionMap = {},\n mainFields = [\"main\"],\n conditions = [_default],\n indexName = \"index\",\n modulesDirectoryName = \"node_modules\",\n manifestFileName = \"package.json\",\n isCoreModule = _isCoreModule,\n path = _path,\n fs = _fs,\n}: Options = {}): Options => {\n if (!conditions.includes(_default)) {\n conditions.push(_default);\n }\n return {\n extensions,\n extensionMap,\n mainFields,\n conditions,\n indexName,\n modulesDirectoryName,\n manifestFileName,\n path,\n fs,\n isCoreModule,\n };\n};\n"],"names":["isNodeProto","id","coreModuleSet","builtinModules","index","_isCoreModule","_fs: {\n stat: (path: any) => {\n exists: boolean;\n isDir: boolean;\n size: number;\n mtime: number;\n };\n readFile: (path: any) => string;\n}","info","statSync","path","readFileSync","_path: {\n dir: (path: string) => string;\n join: (...paths: string[]) => string;\n}","dir","_default","normalizeOptions","_path","_fs","conditions"],"mappings":"gJAIA,MAAMA,EAAe,GAAeC,EAAG,WAAW,SAE5CC,EAAgB,IAAI,IACxBC,EACG,OAAQ,GAAO,CAACH,EAAYC,IAC5B,IAAK,GAAO,CACX,IAAMG,EAAQH,EAAG,QAAQ,KACzB,OAAOG,IAAU,GAAKH,EAAKA,EAAG,UAAU,EAAGG,MAI3CC,EAAiB,GAAeL,EAAYC,IAAOC,EAAc,IAAID,GAErEK,EAQF,CACF,KAAO,GAAS,CACd,GAAI,CACF,IAAMC,EAAOC,EAASC,GACtB,MAAO,CACL,OAAQ,GACR,MAAOF,EAAK,cACZ,KAAMA,EAAK,KACX,MAAOA,EAAK,cAER,CACN,MAAO,CACL,OAAQ,GACR,MAAO,GACP,KAAM,EACN,MAAO,KAIb,SAAW,GACFG,EAAaD,GAAM,SAAS,WAIjCE,EAGF,CACF,IAAAC,EACA,QAGIC,EAAW,UAeJC,GAAoB,CAC/B,aAAa,CAAC,OACd,eAAe,GACf,aAAa,CAAC,QACd,aAAa,CAACD,GACd,YAAY,QACZ,uBAAuB,eACvB,mBAAmB,eACnB,eAAeR,EACf,OAAOU,EACP,KAAKC,GACM,MACNC,EAAW,SAASJ,IACvBI,EAAW,KAAKJ,GAEX,CACL,aACA,eACA,aACA,aACA,YACA,uBACA,mBACA,OACA,KACA"}
|
package/wasm_exec.cjs
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
"use strict";const e=()=>{let e=Error(`not implemented`);return e.code=`ENOSYS`,e};if(!globalThis.fs){let t=``;globalThis.fs={constants:{O_WRONLY:-1,O_RDWR:-1,O_CREAT:-1,O_TRUNC:-1,O_APPEND:-1,O_EXCL:-1,O_DIRECTORY:-1},writeSync(e,r){t+=n.decode(r);let i=t.lastIndexOf(`
|
|
2
|
+
`);return i!=-1&&(console.log(t.substring(0,i)),t=t.substring(i+1)),r.length},write(t,n,r,i,a,o){if(r!==0||i!==n.length||a!==null){o(e());return}let s=this.writeSync(t,n);o(null,s)}}}if(!globalThis.crypto)throw Error(`globalThis.crypto is not available, polyfill required (crypto.getRandomValues only)`);if(!globalThis.performance)throw Error(`globalThis.performance is not available, polyfill required (performance.now only)`);if(!globalThis.TextEncoder)throw Error(`globalThis.TextEncoder is not available, polyfill required`);if(!globalThis.TextDecoder)throw Error(`globalThis.TextDecoder is not available, polyfill required`);const t=new TextEncoder(`utf-8`),n=new TextDecoder(`utf-8`);class r{constructor(){this.argv=[`js`],this.env={},this.exit=e=>{e!==0&&console.warn(`exit code:`,e)},this._exitPromise=new Promise(e=>{this._resolveExitPromise=e}),this._pendingEvent=null,this._scheduledTimeouts=new Map,this._nextCallbackTimeoutID=1;let e=(e,t)=>{this.mem.setUint32(e+0,t,!0),this.mem.setUint32(e+4,Math.floor(t/4294967296),!0)},r=e=>{let t=this.mem.getUint32(e+0,!0),n=this.mem.getInt32(e+4,!0);return t+n*4294967296},i=e=>{let t=this.mem.getFloat64(e,!0);if(t===0)return;if(!isNaN(t))return t;let n=this.mem.getUint32(e,!0);return this._values[n]},a=(e,t)=>{let n=2146959360;if(typeof t==`number`&&t!==0){if(isNaN(t)){this.mem.setUint32(e+4,n,!0),this.mem.setUint32(e,0,!0);return}this.mem.setFloat64(e,t,!0);return}if(t===void 0){this.mem.setFloat64(e,0,!0);return}let r=this._ids.get(t);r===void 0&&(r=this._idPool.pop(),r===void 0&&(r=this._values.length),this._values[r]=t,this._goRefCounts[r]=0,this._ids.set(t,r)),this._goRefCounts[r]++;let i=0;switch(typeof t){case`object`:t!==null&&(i=1);break;case`string`:i=2;break;case`symbol`:i=3;break;case`function`:i=4;break}this.mem.setUint32(e+4,n|i,!0),this.mem.setUint32(e,r,!0)},o=e=>{let t=r(e+0),n=r(e+8);return new Uint8Array(this._inst.exports.mem.buffer,t,n)},s=e=>{let t=r(e+0),n=r(e+8),a=Array(n);for(let e=0;e<n;e++)a[e]=i(t+e*8);return a},c=e=>{let t=r(e+0),i=r(e+8);return n.decode(new DataView(this._inst.exports.mem.buffer,t,i))},l=(e,t)=>(this._inst.exports.testExport0(),this._inst.exports.testExport(e,t)),u=Date.now()-performance.now();this.importObject={_gotest:{add:(e,t)=>e+t,callExport:l},gojs:{"runtime.wasmExit":e=>{e>>>=0;let t=this.mem.getInt32(e+8,!0);this.exited=!0,delete this._inst,delete this._values,delete this._goRefCounts,delete this._ids,delete this._idPool,this.exit(t)},"runtime.wasmWrite":e=>{e>>>=0;let t=r(e+8),n=r(e+16),i=this.mem.getInt32(e+24,!0);fs.writeSync(t,new Uint8Array(this._inst.exports.mem.buffer,n,i))},"runtime.resetMemoryDataView":e=>{this.mem=new DataView(this._inst.exports.mem.buffer)},"runtime.nanotime1":t=>{t>>>=0,e(t+8,(u+performance.now())*1e6)},"runtime.walltime":t=>{t>>>=0;let n=new Date().getTime();e(t+8,n/1e3),this.mem.setInt32(t+16,n%1e3*1e6,!0)},"runtime.scheduleTimeoutEvent":e=>{e>>>=0;let t=this._nextCallbackTimeoutID;this._nextCallbackTimeoutID++,this._scheduledTimeouts.set(t,setTimeout(()=>{for(this._resume();this._scheduledTimeouts.has(t);)console.warn(`scheduleTimeoutEvent: missed timeout event`),this._resume()},r(e+8))),this.mem.setInt32(e+16,t,!0)},"runtime.clearTimeoutEvent":e=>{e>>>=0;let t=this.mem.getInt32(e+8,!0);clearTimeout(this._scheduledTimeouts.get(t)),this._scheduledTimeouts.delete(t)},"runtime.getRandomData":e=>{e>>>=0,crypto.getRandomValues(o(e+8))},"syscall/js.finalizeRef":e=>{e>>>=0;let t=this.mem.getUint32(e+8,!0);if(this._goRefCounts[t]--,this._goRefCounts[t]===0){let e=this._values[t];this._values[t]=null,this._ids.delete(e),this._idPool.push(t)}},"syscall/js.stringVal":e=>{e>>>=0,a(e+24,c(e+8))},"syscall/js.valueGet":e=>{e>>>=0;let t=Reflect.get(i(e+8),c(e+16));e=this._inst.exports.getsp()>>>0,a(e+32,t)},"syscall/js.valueSet":e=>{e>>>=0,Reflect.set(i(e+8),c(e+16),i(e+32))},"syscall/js.valueDelete":e=>{e>>>=0,Reflect.deleteProperty(i(e+8),c(e+16))},"syscall/js.valueIndex":e=>{e>>>=0,a(e+24,Reflect.get(i(e+8),r(e+16)))},"syscall/js.valueSetIndex":e=>{e>>>=0,Reflect.set(i(e+8),r(e+16),i(e+24))},"syscall/js.valueCall":e=>{e>>>=0;try{let t=i(e+8),n=Reflect.get(t,c(e+16)),r=s(e+32),o=Reflect.apply(n,t,r);e=this._inst.exports.getsp()>>>0,a(e+56,o),this.mem.setUint8(e+64,1)}catch(t){e=this._inst.exports.getsp()>>>0,a(e+56,t),this.mem.setUint8(e+64,0)}},"syscall/js.valueInvoke":e=>{e>>>=0;try{let t=i(e+8),n=s(e+16),r=Reflect.apply(t,void 0,n);e=this._inst.exports.getsp()>>>0,a(e+40,r),this.mem.setUint8(e+48,1)}catch(t){e=this._inst.exports.getsp()>>>0,a(e+40,t),this.mem.setUint8(e+48,0)}},"syscall/js.valueNew":e=>{e>>>=0;try{let t=i(e+8),n=s(e+16),r=Reflect.construct(t,n);e=this._inst.exports.getsp()>>>0,a(e+40,r),this.mem.setUint8(e+48,1)}catch(t){e=this._inst.exports.getsp()>>>0,a(e+40,t),this.mem.setUint8(e+48,0)}},"syscall/js.valueLength":t=>{t>>>=0,e(t+16,parseInt(i(t+8).length))},"syscall/js.valuePrepareString":n=>{n>>>=0;let r=t.encode(String(i(n+8)));a(n+16,r),e(n+24,r.length)},"syscall/js.valueLoadString":e=>{e>>>=0;let t=i(e+8);o(e+16).set(t)},"syscall/js.valueInstanceOf":e=>{e>>>=0,this.mem.setUint8(e+24,i(e+8)instanceof i(e+16)?1:0)},"syscall/js.copyBytesToGo":t=>{t>>>=0;let n=o(t+8),r=i(t+32);if(!(r instanceof Uint8Array||r instanceof Uint8ClampedArray)){this.mem.setUint8(t+48,0);return}let a=r.subarray(0,n.length);n.set(a),e(t+40,a.length),this.mem.setUint8(t+48,1)},"syscall/js.copyBytesToJS":t=>{t>>>=0;let n=i(t+8),r=o(t+16);if(!(n instanceof Uint8Array||n instanceof Uint8ClampedArray)){this.mem.setUint8(t+48,0);return}let a=r.subarray(0,n.length);n.set(a),e(t+40,a.length),this.mem.setUint8(t+48,1)},debug:e=>{console.log(e)}}}}async run(e){if(!(e instanceof WebAssembly.Instance))throw Error(`Go.run: WebAssembly.Instance expected`);this._inst=e,this.mem=new DataView(this._inst.exports.mem.buffer),this._values=[NaN,0,null,!0,!1,globalThis,this],this._goRefCounts=Array(this._values.length).fill(1/0),this._ids=new Map([[0,1],[null,2],[!0,3],[!1,4],[globalThis,5],[this,6]]),this._idPool=[],this.exited=!1;let n=4096,r=e=>{let r=n,i=t.encode(e+`\0`);return new Uint8Array(this.mem.buffer,n,i.length).set(i),n+=i.length,n%8!=0&&(n+=8-n%8),r},i=this.argv.length,a=[];this.argv.forEach(e=>{a.push(r(e))}),a.push(0);let o=Object.keys(this.env).sort();o.forEach(e=>{a.push(r(`${e}=${this.env[e]}`))}),a.push(0);let s=n;a.forEach(e=>{this.mem.setUint32(n,e,!0),this.mem.setUint32(n+4,0,!0),n+=8});let c=12288;if(n>=12288)throw Error(`total length of command line and environment variables exceeds limit`);this._inst.exports.run(i,s),this.exited&&this._resolveExitPromise(),await this._exitPromise}_resume(){if(this.exited)throw Error(`Go program has already exited`);this._inst.exports.resume(),this.exited&&this._resolveExitPromise()}_makeFuncWrapper(e){let t=this;return function(){let n={id:e,this:this,args:arguments};return t._pendingEvent=n,t._resume(),n.result}}}exports.Go=r;
|
|
3
|
+
//# sourceMappingURL=wasm_exec.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wasm_exec.cjs","sources":["../src/wasm_exec.js"],"sourcesContent":["const enosys = () => {\n const err = new Error(\"not implemented\");\n err.code = \"ENOSYS\";\n return err;\n};\n\nif (!globalThis.fs) {\n let outputBuf = \"\";\n globalThis.fs = {\n constants: {\n O_WRONLY: -1,\n O_RDWR: -1,\n O_CREAT: -1,\n O_TRUNC: -1,\n O_APPEND: -1,\n O_EXCL: -1,\n O_DIRECTORY: -1,\n }, // unused\n writeSync(fd, buf) {\n outputBuf += decoder.decode(buf);\n const nl = outputBuf.lastIndexOf(\"\\n\");\n if (nl != -1) {\n console.log(outputBuf.substring(0, nl));\n outputBuf = outputBuf.substring(nl + 1);\n }\n return buf.length;\n },\n write(fd, buf, offset, length, position, callback) {\n if (offset !== 0 || length !== buf.length || position !== null) {\n callback(enosys());\n return;\n }\n const n = this.writeSync(fd, buf);\n callback(null, n);\n },\n };\n}\n\nif (!globalThis.crypto) {\n throw new Error(\n \"globalThis.crypto is not available, polyfill required (crypto.getRandomValues only)\",\n );\n}\n\nif (!globalThis.performance) {\n throw new Error(\n \"globalThis.performance is not available, polyfill required (performance.now only)\",\n );\n}\n\nif (!globalThis.TextEncoder) {\n throw new Error(\"globalThis.TextEncoder is not available, polyfill required\");\n}\n\nif (!globalThis.TextDecoder) {\n throw new Error(\"globalThis.TextDecoder is not available, polyfill required\");\n}\n\nconst encoder = new TextEncoder(\"utf-8\");\nconst decoder = new TextDecoder(\"utf-8\");\n\nexport class Go {\n constructor() {\n this.argv = [\"js\"];\n this.env = {};\n this.exit = (code) => {\n if (code !== 0) {\n console.warn(\"exit code:\", code);\n }\n };\n this._exitPromise = new Promise((resolve) => {\n this._resolveExitPromise = resolve;\n });\n this._pendingEvent = null;\n this._scheduledTimeouts = new Map();\n this._nextCallbackTimeoutID = 1;\n\n const setInt64 = (addr, v) => {\n this.mem.setUint32(addr + 0, v, true);\n this.mem.setUint32(addr + 4, Math.floor(v / 4294967296), true);\n };\n\n const setInt32 = (addr, v) => {\n this.mem.setUint32(addr + 0, v, true);\n };\n\n const getInt64 = (addr) => {\n const low = this.mem.getUint32(addr + 0, true);\n const high = this.mem.getInt32(addr + 4, true);\n return low + high * 4294967296;\n };\n\n const loadValue = (addr) => {\n const f = this.mem.getFloat64(addr, true);\n if (f === 0) {\n return undefined;\n }\n if (!isNaN(f)) {\n return f;\n }\n\n const id = this.mem.getUint32(addr, true);\n return this._values[id];\n };\n\n const storeValue = (addr, v) => {\n const nanHead = 0x7ff80000;\n\n if (typeof v === \"number\" && v !== 0) {\n if (isNaN(v)) {\n this.mem.setUint32(addr + 4, nanHead, true);\n this.mem.setUint32(addr, 0, true);\n return;\n }\n this.mem.setFloat64(addr, v, true);\n return;\n }\n\n if (v === undefined) {\n this.mem.setFloat64(addr, 0, true);\n return;\n }\n\n let id = this._ids.get(v);\n if (id === undefined) {\n id = this._idPool.pop();\n if (id === undefined) {\n id = this._values.length;\n }\n this._values[id] = v;\n this._goRefCounts[id] = 0;\n this._ids.set(v, id);\n }\n this._goRefCounts[id]++;\n let typeFlag = 0;\n switch (typeof v) {\n case \"object\":\n if (v !== null) {\n typeFlag = 1;\n }\n break;\n case \"string\":\n typeFlag = 2;\n break;\n case \"symbol\":\n typeFlag = 3;\n break;\n case \"function\":\n typeFlag = 4;\n break;\n }\n this.mem.setUint32(addr + 4, nanHead | typeFlag, true);\n this.mem.setUint32(addr, id, true);\n };\n\n const loadSlice = (addr) => {\n const array = getInt64(addr + 0);\n const len = getInt64(addr + 8);\n return new Uint8Array(this._inst.exports.mem.buffer, array, len);\n };\n\n const loadSliceOfValues = (addr) => {\n const array = getInt64(addr + 0);\n const len = getInt64(addr + 8);\n const a = new Array(len);\n for (let i = 0; i < len; i++) {\n a[i] = loadValue(array + i * 8);\n }\n return a;\n };\n\n const loadString = (addr) => {\n const saddr = getInt64(addr + 0);\n const len = getInt64(addr + 8);\n return decoder.decode(new DataView(this._inst.exports.mem.buffer, saddr, len));\n };\n\n const testCallExport = (a, b) => {\n this._inst.exports.testExport0();\n return this._inst.exports.testExport(a, b);\n };\n\n const timeOrigin = Date.now() - performance.now();\n this.importObject = {\n _gotest: {\n add: (a, b) => a + b,\n callExport: testCallExport,\n },\n gojs: {\n // Go's SP does not change as long as no Go code is running. Some operations (e.g. calls, getters and setters)\n // may synchronously trigger a Go event handler. This makes Go code get executed in the middle of the imported\n // function. A goroutine can switch to a new stack if the current stack is too small (see morestack function).\n // This changes the SP, thus we have to update the SP used by the imported function.\n\n // func wasmExit(code int32)\n \"runtime.wasmExit\": (sp) => {\n sp >>>= 0;\n const code = this.mem.getInt32(sp + 8, true);\n this.exited = true;\n delete this._inst;\n delete this._values;\n delete this._goRefCounts;\n delete this._ids;\n delete this._idPool;\n this.exit(code);\n },\n\n // func wasmWrite(fd uintptr, p unsafe.Pointer, n int32)\n \"runtime.wasmWrite\": (sp) => {\n sp >>>= 0;\n const fd = getInt64(sp + 8);\n const p = getInt64(sp + 16);\n const n = this.mem.getInt32(sp + 24, true);\n fs.writeSync(fd, new Uint8Array(this._inst.exports.mem.buffer, p, n));\n },\n\n // func resetMemoryDataView()\n \"runtime.resetMemoryDataView\": (sp) => {\n sp >>>= 0;\n this.mem = new DataView(this._inst.exports.mem.buffer);\n },\n\n // func nanotime1() int64\n \"runtime.nanotime1\": (sp) => {\n sp >>>= 0;\n setInt64(sp + 8, (timeOrigin + performance.now()) * 1000000);\n },\n\n // func walltime() (sec int64, nsec int32)\n \"runtime.walltime\": (sp) => {\n sp >>>= 0;\n const msec = new Date().getTime();\n setInt64(sp + 8, msec / 1000);\n this.mem.setInt32(sp + 16, (msec % 1000) * 1000000, true);\n },\n\n // func scheduleTimeoutEvent(delay int64) int32\n \"runtime.scheduleTimeoutEvent\": (sp) => {\n sp >>>= 0;\n const id = this._nextCallbackTimeoutID;\n this._nextCallbackTimeoutID++;\n this._scheduledTimeouts.set(\n id,\n setTimeout(\n () => {\n this._resume();\n while (this._scheduledTimeouts.has(id)) {\n // for some reason Go failed to register the timeout event, log and try again\n // (temporary workaround for https://github.com/golang/go/issues/28975)\n console.warn(\"scheduleTimeoutEvent: missed timeout event\");\n this._resume();\n }\n },\n getInt64(sp + 8),\n ),\n );\n this.mem.setInt32(sp + 16, id, true);\n },\n\n // func clearTimeoutEvent(id int32)\n \"runtime.clearTimeoutEvent\": (sp) => {\n sp >>>= 0;\n const id = this.mem.getInt32(sp + 8, true);\n clearTimeout(this._scheduledTimeouts.get(id));\n this._scheduledTimeouts.delete(id);\n },\n\n // func getRandomData(r []byte)\n \"runtime.getRandomData\": (sp) => {\n sp >>>= 0;\n crypto.getRandomValues(loadSlice(sp + 8));\n },\n\n // func finalizeRef(v ref)\n \"syscall/js.finalizeRef\": (sp) => {\n sp >>>= 0;\n const id = this.mem.getUint32(sp + 8, true);\n this._goRefCounts[id]--;\n if (this._goRefCounts[id] === 0) {\n const v = this._values[id];\n this._values[id] = null;\n this._ids.delete(v);\n this._idPool.push(id);\n }\n },\n\n // func stringVal(value string) ref\n \"syscall/js.stringVal\": (sp) => {\n sp >>>= 0;\n storeValue(sp + 24, loadString(sp + 8));\n },\n\n // func valueGet(v ref, p string) ref\n \"syscall/js.valueGet\": (sp) => {\n sp >>>= 0;\n const result = Reflect.get(loadValue(sp + 8), loadString(sp + 16));\n sp = this._inst.exports.getsp() >>> 0; // see comment above\n storeValue(sp + 32, result);\n },\n\n // func valueSet(v ref, p string, x ref)\n \"syscall/js.valueSet\": (sp) => {\n sp >>>= 0;\n Reflect.set(loadValue(sp + 8), loadString(sp + 16), loadValue(sp + 32));\n },\n\n // func valueDelete(v ref, p string)\n \"syscall/js.valueDelete\": (sp) => {\n sp >>>= 0;\n Reflect.deleteProperty(loadValue(sp + 8), loadString(sp + 16));\n },\n\n // func valueIndex(v ref, i int) ref\n \"syscall/js.valueIndex\": (sp) => {\n sp >>>= 0;\n storeValue(sp + 24, Reflect.get(loadValue(sp + 8), getInt64(sp + 16)));\n },\n\n // valueSetIndex(v ref, i int, x ref)\n \"syscall/js.valueSetIndex\": (sp) => {\n sp >>>= 0;\n Reflect.set(loadValue(sp + 8), getInt64(sp + 16), loadValue(sp + 24));\n },\n\n // func valueCall(v ref, m string, args []ref) (ref, bool)\n \"syscall/js.valueCall\": (sp) => {\n sp >>>= 0;\n try {\n const v = loadValue(sp + 8);\n const m = Reflect.get(v, loadString(sp + 16));\n const args = loadSliceOfValues(sp + 32);\n const result = Reflect.apply(m, v, args);\n sp = this._inst.exports.getsp() >>> 0; // see comment above\n storeValue(sp + 56, result);\n this.mem.setUint8(sp + 64, 1);\n } catch (err) {\n sp = this._inst.exports.getsp() >>> 0; // see comment above\n storeValue(sp + 56, err);\n this.mem.setUint8(sp + 64, 0);\n }\n },\n\n // func valueInvoke(v ref, args []ref) (ref, bool)\n \"syscall/js.valueInvoke\": (sp) => {\n sp >>>= 0;\n try {\n const v = loadValue(sp + 8);\n const args = loadSliceOfValues(sp + 16);\n const result = Reflect.apply(v, undefined, args);\n sp = this._inst.exports.getsp() >>> 0; // see comment above\n storeValue(sp + 40, result);\n this.mem.setUint8(sp + 48, 1);\n } catch (err) {\n sp = this._inst.exports.getsp() >>> 0; // see comment above\n storeValue(sp + 40, err);\n this.mem.setUint8(sp + 48, 0);\n }\n },\n\n // func valueNew(v ref, args []ref) (ref, bool)\n \"syscall/js.valueNew\": (sp) => {\n sp >>>= 0;\n try {\n const v = loadValue(sp + 8);\n const args = loadSliceOfValues(sp + 16);\n const result = Reflect.construct(v, args);\n sp = this._inst.exports.getsp() >>> 0; // see comment above\n storeValue(sp + 40, result);\n this.mem.setUint8(sp + 48, 1);\n } catch (err) {\n sp = this._inst.exports.getsp() >>> 0; // see comment above\n storeValue(sp + 40, err);\n this.mem.setUint8(sp + 48, 0);\n }\n },\n\n // func valueLength(v ref) int\n \"syscall/js.valueLength\": (sp) => {\n sp >>>= 0;\n setInt64(sp + 16, parseInt(loadValue(sp + 8).length));\n },\n\n // valuePrepareString(v ref) (ref, int)\n \"syscall/js.valuePrepareString\": (sp) => {\n sp >>>= 0;\n const str = encoder.encode(String(loadValue(sp + 8)));\n storeValue(sp + 16, str);\n setInt64(sp + 24, str.length);\n },\n\n // valueLoadString(v ref, b []byte)\n \"syscall/js.valueLoadString\": (sp) => {\n sp >>>= 0;\n const str = loadValue(sp + 8);\n loadSlice(sp + 16).set(str);\n },\n\n // func valueInstanceOf(v ref, t ref) bool\n \"syscall/js.valueInstanceOf\": (sp) => {\n sp >>>= 0;\n this.mem.setUint8(sp + 24, loadValue(sp + 8) instanceof loadValue(sp + 16) ? 1 : 0);\n },\n\n // func copyBytesToGo(dst []byte, src ref) (int, bool)\n \"syscall/js.copyBytesToGo\": (sp) => {\n sp >>>= 0;\n const dst = loadSlice(sp + 8);\n const src = loadValue(sp + 32);\n if (!(src instanceof Uint8Array || src instanceof Uint8ClampedArray)) {\n this.mem.setUint8(sp + 48, 0);\n return;\n }\n const toCopy = src.subarray(0, dst.length);\n dst.set(toCopy);\n setInt64(sp + 40, toCopy.length);\n this.mem.setUint8(sp + 48, 1);\n },\n\n // func copyBytesToJS(dst ref, src []byte) (int, bool)\n \"syscall/js.copyBytesToJS\": (sp) => {\n sp >>>= 0;\n const dst = loadValue(sp + 8);\n const src = loadSlice(sp + 16);\n if (!(dst instanceof Uint8Array || dst instanceof Uint8ClampedArray)) {\n this.mem.setUint8(sp + 48, 0);\n return;\n }\n const toCopy = src.subarray(0, dst.length);\n dst.set(toCopy);\n setInt64(sp + 40, toCopy.length);\n this.mem.setUint8(sp + 48, 1);\n },\n\n debug: (value) => {\n console.log(value);\n },\n },\n };\n }\n\n async run(instance) {\n if (!(instance instanceof WebAssembly.Instance)) {\n throw new Error(\"Go.run: WebAssembly.Instance expected\");\n }\n this._inst = instance;\n this.mem = new DataView(this._inst.exports.mem.buffer);\n this._values = [\n // JS values that Go currently has references to, indexed by reference id\n NaN,\n 0,\n null,\n true,\n false,\n globalThis,\n this,\n ];\n this._goRefCounts = new Array(this._values.length).fill(Infinity); // number of references that Go has to a JS value, indexed by reference id\n this._ids = new Map([\n // mapping from JS values to reference ids\n [0, 1],\n [null, 2],\n [true, 3],\n [false, 4],\n [globalThis, 5],\n [this, 6],\n ]);\n this._idPool = []; // unused ids that have been garbage collected\n this.exited = false; // whether the Go program has exited\n\n // Pass command line arguments and environment variables to WebAssembly by writing them to the linear memory.\n let offset = 4096;\n\n const strPtr = (str) => {\n const ptr = offset;\n const bytes = encoder.encode(str + \"\\0\");\n new Uint8Array(this.mem.buffer, offset, bytes.length).set(bytes);\n offset += bytes.length;\n if (offset % 8 !== 0) {\n offset += 8 - (offset % 8);\n }\n return ptr;\n };\n\n const argc = this.argv.length;\n\n const argvPtrs = [];\n this.argv.forEach((arg) => {\n argvPtrs.push(strPtr(arg));\n });\n argvPtrs.push(0);\n\n const keys = Object.keys(this.env).sort();\n keys.forEach((key) => {\n argvPtrs.push(strPtr(`${key}=${this.env[key]}`));\n });\n argvPtrs.push(0);\n\n const argv = offset;\n argvPtrs.forEach((ptr) => {\n this.mem.setUint32(offset, ptr, true);\n this.mem.setUint32(offset + 4, 0, true);\n offset += 8;\n });\n\n // The linker guarantees global data starts from at least wasmMinDataAddr.\n // Keep in sync with cmd/link/internal/ld/data.go:wasmMinDataAddr.\n const wasmMinDataAddr = 4096 + 8192;\n if (offset >= wasmMinDataAddr) {\n throw new Error(\"total length of command line and environment variables exceeds limit\");\n }\n\n this._inst.exports.run(argc, argv);\n if (this.exited) {\n this._resolveExitPromise();\n }\n await this._exitPromise;\n }\n\n _resume() {\n if (this.exited) {\n throw new Error(\"Go program has already exited\");\n }\n this._inst.exports.resume();\n if (this.exited) {\n this._resolveExitPromise();\n }\n }\n\n _makeFuncWrapper(id) {\n const go = this;\n return function () {\n const event = { id: id, this: this, args: arguments };\n go._pendingEvent = event;\n go._resume();\n return event.result;\n };\n }\n}\n"],"names":["enosys","err","outputBuf","decoder","buf","nl","offset","length","position","callback","n","fd","encoder","Go","code","resolve","setInt64","addr","v","getInt64","low","high","loadValue","f","id","storeValue","nanHead","typeFlag","loadSlice","array","len","loadSliceOfValues","i","loadString","saddr","testCallExport","a","b","timeOrigin","sp","p","msec","result","m","args","str","dst","src","toCopy","value","instance","strPtr","ptr","bytes","argc","argvPtrs","arg","keys","key","argv","wasmMinDataAddr","go","event"],"mappings":"aAAA,MAAMA,MAAe,CACnB,IAAMC,EAAU,MAAM,mBAEtB,MADA,GAAI,KAAO,SACJA,GAGT,GAAI,CAAC,WAAW,GAAI,CAClB,IAAIC,EAAY,GAChB,WAAW,GAAK,CACd,UAAW,CACT,SAAU,GACV,OAAQ,GACR,QAAS,GACT,QAAS,GACT,SAAU,GACV,OAAQ,GACR,YAAa,IAEf,UAAU,EAAI,EAAK,CACjB,GAAaC,EAAQ,OAAOC,GAC5B,IAAMC,EAAKH,EAAU,YAAY;GAKjC,OAJIG,GAAM,KACR,QAAQ,IAAIH,EAAU,UAAU,EAAGG,IACnC,EAAYH,EAAU,UAAUG,EAAK,IAEhCD,EAAI,QAEb,MAAM,EAAI,EAAK,EAAQ,EAAQ,EAAU,EAAU,CACjD,GAAIE,IAAW,GAAKC,IAAWH,EAAI,QAAUI,IAAa,KAAM,CAC9DC,EAAST,KACT,OAEF,IAAMU,EAAI,KAAK,UAAUC,EAAIP,GAC7BK,EAAS,KAAMC,KAKrB,GAAI,CAAC,WAAW,OACd,MAAU,MACR,uFAIJ,GAAI,CAAC,WAAW,YACd,MAAU,MACR,qFAIJ,GAAI,CAAC,WAAW,YACd,MAAU,MAAM,8DAGlB,GAAI,CAAC,WAAW,YACd,MAAU,MAAM,8DAGlB,MAAME,EAAU,IAAI,YAAY,SAC1BT,EAAU,IAAI,YAAY,SAEzB,MAAMU,CAAG,CACd,aAAc,CACZ,KAAK,KAAO,CAAC,MACb,KAAK,IAAM,GACX,KAAK,KAAQ,GAAS,CAChBC,IAAS,GACX,QAAQ,KAAK,aAAcA,IAG/B,KAAK,aAAe,IAAI,QAAS,GAAY,CAC3C,KAAK,oBAAsBC,IAE7B,KAAK,cAAgB,KACrB,KAAK,mBAAqB,IAAI,IAC9B,KAAK,uBAAyB,EAE9B,IAAMC,GAAY,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GAEd,IAAMI,EAAOrD,EACbiD,EAAS,QAAS,GAAQ,CACxB,KAAK,IAAI,UAAUjD,EAAQ8C,EAAK,IAChC,KAAK,IAAI,UAAU9C,EAAS,EAAG,EAAG,IAClC,GAAU,IAKZ,IAAMsD,EAAkB,MACxB,GAAItD,GAAU,MACZ,MAAU,MAAM,wEAGlB,KAAK,MAAM,QAAQ,IAAIgD,EAAMK,GACzB,KAAK,QACP,KAAK,sBAEP,MAAM,KAAK,aAGb,SAAU,CACR,GAAI,KAAK,OACP,MAAU,MAAM,iCAElB,KAAK,MAAM,QAAQ,SACf,KAAK,QACP,KAAK,sBAIT,iBAAiB,EAAI,CACnB,IAAME,EAAK,KACX,OAAO,UAAY,CACjB,IAAMC,EAAQ,CAAM,KAAI,KAAM,KAAM,KAAM,WAG1C,MAFA,GAAG,cAAgBA,EACnBD,EAAG,UACIC,EAAM"}
|
package/wasm_exec.mjs
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
const e=()=>{let e=Error(`not implemented`);return e.code=`ENOSYS`,e};if(!globalThis.fs){let t=``;globalThis.fs={constants:{O_WRONLY:-1,O_RDWR:-1,O_CREAT:-1,O_TRUNC:-1,O_APPEND:-1,O_EXCL:-1,O_DIRECTORY:-1},writeSync(e,r){t+=n.decode(r);let i=t.lastIndexOf(`
|
|
2
|
+
`);return i!=-1&&(console.log(t.substring(0,i)),t=t.substring(i+1)),r.length},write(t,n,r,i,a,o){if(r!==0||i!==n.length||a!==null){o(e());return}let s=this.writeSync(t,n);o(null,s)}}}if(!globalThis.crypto)throw Error(`globalThis.crypto is not available, polyfill required (crypto.getRandomValues only)`);if(!globalThis.performance)throw Error(`globalThis.performance is not available, polyfill required (performance.now only)`);if(!globalThis.TextEncoder)throw Error(`globalThis.TextEncoder is not available, polyfill required`);if(!globalThis.TextDecoder)throw Error(`globalThis.TextDecoder is not available, polyfill required`);const t=new TextEncoder(`utf-8`),n=new TextDecoder(`utf-8`);class r{constructor(){this.argv=[`js`],this.env={},this.exit=e=>{e!==0&&console.warn(`exit code:`,e)},this._exitPromise=new Promise(e=>{this._resolveExitPromise=e}),this._pendingEvent=null,this._scheduledTimeouts=new Map,this._nextCallbackTimeoutID=1;let e=(e,t)=>{this.mem.setUint32(e+0,t,!0),this.mem.setUint32(e+4,Math.floor(t/4294967296),!0)},r=e=>{let t=this.mem.getUint32(e+0,!0),n=this.mem.getInt32(e+4,!0);return t+n*4294967296},i=e=>{let t=this.mem.getFloat64(e,!0);if(t===0)return;if(!isNaN(t))return t;let n=this.mem.getUint32(e,!0);return this._values[n]},a=(e,t)=>{let n=2146959360;if(typeof t==`number`&&t!==0){if(isNaN(t)){this.mem.setUint32(e+4,n,!0),this.mem.setUint32(e,0,!0);return}this.mem.setFloat64(e,t,!0);return}if(t===void 0){this.mem.setFloat64(e,0,!0);return}let r=this._ids.get(t);r===void 0&&(r=this._idPool.pop(),r===void 0&&(r=this._values.length),this._values[r]=t,this._goRefCounts[r]=0,this._ids.set(t,r)),this._goRefCounts[r]++;let i=0;switch(typeof t){case`object`:t!==null&&(i=1);break;case`string`:i=2;break;case`symbol`:i=3;break;case`function`:i=4;break}this.mem.setUint32(e+4,n|i,!0),this.mem.setUint32(e,r,!0)},o=e=>{let t=r(e+0),n=r(e+8);return new Uint8Array(this._inst.exports.mem.buffer,t,n)},s=e=>{let t=r(e+0),n=r(e+8),a=Array(n);for(let e=0;e<n;e++)a[e]=i(t+e*8);return a},c=e=>{let t=r(e+0),i=r(e+8);return n.decode(new DataView(this._inst.exports.mem.buffer,t,i))},l=(e,t)=>(this._inst.exports.testExport0(),this._inst.exports.testExport(e,t)),u=Date.now()-performance.now();this.importObject={_gotest:{add:(e,t)=>e+t,callExport:l},gojs:{"runtime.wasmExit":e=>{e>>>=0;let t=this.mem.getInt32(e+8,!0);this.exited=!0,delete this._inst,delete this._values,delete this._goRefCounts,delete this._ids,delete this._idPool,this.exit(t)},"runtime.wasmWrite":e=>{e>>>=0;let t=r(e+8),n=r(e+16),i=this.mem.getInt32(e+24,!0);fs.writeSync(t,new Uint8Array(this._inst.exports.mem.buffer,n,i))},"runtime.resetMemoryDataView":e=>{this.mem=new DataView(this._inst.exports.mem.buffer)},"runtime.nanotime1":t=>{t>>>=0,e(t+8,(u+performance.now())*1e6)},"runtime.walltime":t=>{t>>>=0;let n=new Date().getTime();e(t+8,n/1e3),this.mem.setInt32(t+16,n%1e3*1e6,!0)},"runtime.scheduleTimeoutEvent":e=>{e>>>=0;let t=this._nextCallbackTimeoutID;this._nextCallbackTimeoutID++,this._scheduledTimeouts.set(t,setTimeout(()=>{for(this._resume();this._scheduledTimeouts.has(t);)console.warn(`scheduleTimeoutEvent: missed timeout event`),this._resume()},r(e+8))),this.mem.setInt32(e+16,t,!0)},"runtime.clearTimeoutEvent":e=>{e>>>=0;let t=this.mem.getInt32(e+8,!0);clearTimeout(this._scheduledTimeouts.get(t)),this._scheduledTimeouts.delete(t)},"runtime.getRandomData":e=>{e>>>=0,crypto.getRandomValues(o(e+8))},"syscall/js.finalizeRef":e=>{e>>>=0;let t=this.mem.getUint32(e+8,!0);if(this._goRefCounts[t]--,this._goRefCounts[t]===0){let e=this._values[t];this._values[t]=null,this._ids.delete(e),this._idPool.push(t)}},"syscall/js.stringVal":e=>{e>>>=0,a(e+24,c(e+8))},"syscall/js.valueGet":e=>{e>>>=0;let t=Reflect.get(i(e+8),c(e+16));e=this._inst.exports.getsp()>>>0,a(e+32,t)},"syscall/js.valueSet":e=>{e>>>=0,Reflect.set(i(e+8),c(e+16),i(e+32))},"syscall/js.valueDelete":e=>{e>>>=0,Reflect.deleteProperty(i(e+8),c(e+16))},"syscall/js.valueIndex":e=>{e>>>=0,a(e+24,Reflect.get(i(e+8),r(e+16)))},"syscall/js.valueSetIndex":e=>{e>>>=0,Reflect.set(i(e+8),r(e+16),i(e+24))},"syscall/js.valueCall":e=>{e>>>=0;try{let t=i(e+8),n=Reflect.get(t,c(e+16)),r=s(e+32),o=Reflect.apply(n,t,r);e=this._inst.exports.getsp()>>>0,a(e+56,o),this.mem.setUint8(e+64,1)}catch(t){e=this._inst.exports.getsp()>>>0,a(e+56,t),this.mem.setUint8(e+64,0)}},"syscall/js.valueInvoke":e=>{e>>>=0;try{let t=i(e+8),n=s(e+16),r=Reflect.apply(t,void 0,n);e=this._inst.exports.getsp()>>>0,a(e+40,r),this.mem.setUint8(e+48,1)}catch(t){e=this._inst.exports.getsp()>>>0,a(e+40,t),this.mem.setUint8(e+48,0)}},"syscall/js.valueNew":e=>{e>>>=0;try{let t=i(e+8),n=s(e+16),r=Reflect.construct(t,n);e=this._inst.exports.getsp()>>>0,a(e+40,r),this.mem.setUint8(e+48,1)}catch(t){e=this._inst.exports.getsp()>>>0,a(e+40,t),this.mem.setUint8(e+48,0)}},"syscall/js.valueLength":t=>{t>>>=0,e(t+16,parseInt(i(t+8).length))},"syscall/js.valuePrepareString":n=>{n>>>=0;let r=t.encode(String(i(n+8)));a(n+16,r),e(n+24,r.length)},"syscall/js.valueLoadString":e=>{e>>>=0;let t=i(e+8);o(e+16).set(t)},"syscall/js.valueInstanceOf":e=>{e>>>=0,this.mem.setUint8(e+24,i(e+8)instanceof i(e+16)?1:0)},"syscall/js.copyBytesToGo":t=>{t>>>=0;let n=o(t+8),r=i(t+32);if(!(r instanceof Uint8Array||r instanceof Uint8ClampedArray)){this.mem.setUint8(t+48,0);return}let a=r.subarray(0,n.length);n.set(a),e(t+40,a.length),this.mem.setUint8(t+48,1)},"syscall/js.copyBytesToJS":t=>{t>>>=0;let n=i(t+8),r=o(t+16);if(!(n instanceof Uint8Array||n instanceof Uint8ClampedArray)){this.mem.setUint8(t+48,0);return}let a=r.subarray(0,n.length);n.set(a),e(t+40,a.length),this.mem.setUint8(t+48,1)},debug:e=>{console.log(e)}}}}async run(e){if(!(e instanceof WebAssembly.Instance))throw Error(`Go.run: WebAssembly.Instance expected`);this._inst=e,this.mem=new DataView(this._inst.exports.mem.buffer),this._values=[NaN,0,null,!0,!1,globalThis,this],this._goRefCounts=Array(this._values.length).fill(1/0),this._ids=new Map([[0,1],[null,2],[!0,3],[!1,4],[globalThis,5],[this,6]]),this._idPool=[],this.exited=!1;let n=4096,r=e=>{let r=n,i=t.encode(e+`\0`);return new Uint8Array(this.mem.buffer,n,i.length).set(i),n+=i.length,n%8!=0&&(n+=8-n%8),r},i=this.argv.length,a=[];this.argv.forEach(e=>{a.push(r(e))}),a.push(0);let o=Object.keys(this.env).sort();o.forEach(e=>{a.push(r(`${e}=${this.env[e]}`))}),a.push(0);let s=n;a.forEach(e=>{this.mem.setUint32(n,e,!0),this.mem.setUint32(n+4,0,!0),n+=8});let c=12288;if(n>=12288)throw Error(`total length of command line and environment variables exceeds limit`);this._inst.exports.run(i,s),this.exited&&this._resolveExitPromise(),await this._exitPromise}_resume(){if(this.exited)throw Error(`Go program has already exited`);this._inst.exports.resume(),this.exited&&this._resolveExitPromise()}_makeFuncWrapper(e){let t=this;return function(){let n={id:e,this:this,args:arguments};return t._pendingEvent=n,t._resume(),n.result}}}export{r as Go};
|
|
3
|
+
//# sourceMappingURL=wasm_exec.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wasm_exec.mjs","sources":["../src/wasm_exec.js"],"sourcesContent":["const enosys = () => {\n const err = new Error(\"not implemented\");\n err.code = \"ENOSYS\";\n return err;\n};\n\nif (!globalThis.fs) {\n let outputBuf = \"\";\n globalThis.fs = {\n constants: {\n O_WRONLY: -1,\n O_RDWR: -1,\n O_CREAT: -1,\n O_TRUNC: -1,\n O_APPEND: -1,\n O_EXCL: -1,\n O_DIRECTORY: -1,\n }, // unused\n writeSync(fd, buf) {\n outputBuf += decoder.decode(buf);\n const nl = outputBuf.lastIndexOf(\"\\n\");\n if (nl != -1) {\n console.log(outputBuf.substring(0, nl));\n outputBuf = outputBuf.substring(nl + 1);\n }\n return buf.length;\n },\n write(fd, buf, offset, length, position, callback) {\n if (offset !== 0 || length !== buf.length || position !== null) {\n callback(enosys());\n return;\n }\n const n = this.writeSync(fd, buf);\n callback(null, n);\n },\n };\n}\n\nif (!globalThis.crypto) {\n throw new Error(\n \"globalThis.crypto is not available, polyfill required (crypto.getRandomValues only)\",\n );\n}\n\nif (!globalThis.performance) {\n throw new Error(\n \"globalThis.performance is not available, polyfill required (performance.now only)\",\n );\n}\n\nif (!globalThis.TextEncoder) {\n throw new Error(\"globalThis.TextEncoder is not available, polyfill required\");\n}\n\nif (!globalThis.TextDecoder) {\n throw new Error(\"globalThis.TextDecoder is not available, polyfill required\");\n}\n\nconst encoder = new TextEncoder(\"utf-8\");\nconst decoder = new TextDecoder(\"utf-8\");\n\nexport class Go {\n constructor() {\n this.argv = [\"js\"];\n this.env = {};\n this.exit = (code) => {\n if (code !== 0) {\n console.warn(\"exit code:\", code);\n }\n };\n this._exitPromise = new Promise((resolve) => {\n this._resolveExitPromise = resolve;\n });\n this._pendingEvent = null;\n this._scheduledTimeouts = new Map();\n this._nextCallbackTimeoutID = 1;\n\n const setInt64 = (addr, v) => {\n this.mem.setUint32(addr + 0, v, true);\n this.mem.setUint32(addr + 4, Math.floor(v / 4294967296), true);\n };\n\n const setInt32 = (addr, v) => {\n this.mem.setUint32(addr + 0, v, true);\n };\n\n const getInt64 = (addr) => {\n const low = this.mem.getUint32(addr + 0, true);\n const high = this.mem.getInt32(addr + 4, true);\n return low + high * 4294967296;\n };\n\n const loadValue = (addr) => {\n const f = this.mem.getFloat64(addr, true);\n if (f === 0) {\n return undefined;\n }\n if (!isNaN(f)) {\n return f;\n }\n\n const id = this.mem.getUint32(addr, true);\n return this._values[id];\n };\n\n const storeValue = (addr, v) => {\n const nanHead = 0x7ff80000;\n\n if (typeof v === \"number\" && v !== 0) {\n if (isNaN(v)) {\n this.mem.setUint32(addr + 4, nanHead, true);\n this.mem.setUint32(addr, 0, true);\n return;\n }\n this.mem.setFloat64(addr, v, true);\n return;\n }\n\n if (v === undefined) {\n this.mem.setFloat64(addr, 0, true);\n return;\n }\n\n let id = this._ids.get(v);\n if (id === undefined) {\n id = this._idPool.pop();\n if (id === undefined) {\n id = this._values.length;\n }\n this._values[id] = v;\n this._goRefCounts[id] = 0;\n this._ids.set(v, id);\n }\n this._goRefCounts[id]++;\n let typeFlag = 0;\n switch (typeof v) {\n case \"object\":\n if (v !== null) {\n typeFlag = 1;\n }\n break;\n case \"string\":\n typeFlag = 2;\n break;\n case \"symbol\":\n typeFlag = 3;\n break;\n case \"function\":\n typeFlag = 4;\n break;\n }\n this.mem.setUint32(addr + 4, nanHead | typeFlag, true);\n this.mem.setUint32(addr, id, true);\n };\n\n const loadSlice = (addr) => {\n const array = getInt64(addr + 0);\n const len = getInt64(addr + 8);\n return new Uint8Array(this._inst.exports.mem.buffer, array, len);\n };\n\n const loadSliceOfValues = (addr) => {\n const array = getInt64(addr + 0);\n const len = getInt64(addr + 8);\n const a = new Array(len);\n for (let i = 0; i < len; i++) {\n a[i] = loadValue(array + i * 8);\n }\n return a;\n };\n\n const loadString = (addr) => {\n const saddr = getInt64(addr + 0);\n const len = getInt64(addr + 8);\n return decoder.decode(new DataView(this._inst.exports.mem.buffer, saddr, len));\n };\n\n const testCallExport = (a, b) => {\n this._inst.exports.testExport0();\n return this._inst.exports.testExport(a, b);\n };\n\n const timeOrigin = Date.now() - performance.now();\n this.importObject = {\n _gotest: {\n add: (a, b) => a + b,\n callExport: testCallExport,\n },\n gojs: {\n // Go's SP does not change as long as no Go code is running. Some operations (e.g. calls, getters and setters)\n // may synchronously trigger a Go event handler. This makes Go code get executed in the middle of the imported\n // function. A goroutine can switch to a new stack if the current stack is too small (see morestack function).\n // This changes the SP, thus we have to update the SP used by the imported function.\n\n // func wasmExit(code int32)\n \"runtime.wasmExit\": (sp) => {\n sp >>>= 0;\n const code = this.mem.getInt32(sp + 8, true);\n this.exited = true;\n delete this._inst;\n delete this._values;\n delete this._goRefCounts;\n delete this._ids;\n delete this._idPool;\n this.exit(code);\n },\n\n // func wasmWrite(fd uintptr, p unsafe.Pointer, n int32)\n \"runtime.wasmWrite\": (sp) => {\n sp >>>= 0;\n const fd = getInt64(sp + 8);\n const p = getInt64(sp + 16);\n const n = this.mem.getInt32(sp + 24, true);\n fs.writeSync(fd, new Uint8Array(this._inst.exports.mem.buffer, p, n));\n },\n\n // func resetMemoryDataView()\n \"runtime.resetMemoryDataView\": (sp) => {\n sp >>>= 0;\n this.mem = new DataView(this._inst.exports.mem.buffer);\n },\n\n // func nanotime1() int64\n \"runtime.nanotime1\": (sp) => {\n sp >>>= 0;\n setInt64(sp + 8, (timeOrigin + performance.now()) * 1000000);\n },\n\n // func walltime() (sec int64, nsec int32)\n \"runtime.walltime\": (sp) => {\n sp >>>= 0;\n const msec = new Date().getTime();\n setInt64(sp + 8, msec / 1000);\n this.mem.setInt32(sp + 16, (msec % 1000) * 1000000, true);\n },\n\n // func scheduleTimeoutEvent(delay int64) int32\n \"runtime.scheduleTimeoutEvent\": (sp) => {\n sp >>>= 0;\n const id = this._nextCallbackTimeoutID;\n this._nextCallbackTimeoutID++;\n this._scheduledTimeouts.set(\n id,\n setTimeout(\n () => {\n this._resume();\n while (this._scheduledTimeouts.has(id)) {\n // for some reason Go failed to register the timeout event, log and try again\n // (temporary workaround for https://github.com/golang/go/issues/28975)\n console.warn(\"scheduleTimeoutEvent: missed timeout event\");\n this._resume();\n }\n },\n getInt64(sp + 8),\n ),\n );\n this.mem.setInt32(sp + 16, id, true);\n },\n\n // func clearTimeoutEvent(id int32)\n \"runtime.clearTimeoutEvent\": (sp) => {\n sp >>>= 0;\n const id = this.mem.getInt32(sp + 8, true);\n clearTimeout(this._scheduledTimeouts.get(id));\n this._scheduledTimeouts.delete(id);\n },\n\n // func getRandomData(r []byte)\n \"runtime.getRandomData\": (sp) => {\n sp >>>= 0;\n crypto.getRandomValues(loadSlice(sp + 8));\n },\n\n // func finalizeRef(v ref)\n \"syscall/js.finalizeRef\": (sp) => {\n sp >>>= 0;\n const id = this.mem.getUint32(sp + 8, true);\n this._goRefCounts[id]--;\n if (this._goRefCounts[id] === 0) {\n const v = this._values[id];\n this._values[id] = null;\n this._ids.delete(v);\n this._idPool.push(id);\n }\n },\n\n // func stringVal(value string) ref\n \"syscall/js.stringVal\": (sp) => {\n sp >>>= 0;\n storeValue(sp + 24, loadString(sp + 8));\n },\n\n // func valueGet(v ref, p string) ref\n \"syscall/js.valueGet\": (sp) => {\n sp >>>= 0;\n const result = Reflect.get(loadValue(sp + 8), loadString(sp + 16));\n sp = this._inst.exports.getsp() >>> 0; // see comment above\n storeValue(sp + 32, result);\n },\n\n // func valueSet(v ref, p string, x ref)\n \"syscall/js.valueSet\": (sp) => {\n sp >>>= 0;\n Reflect.set(loadValue(sp + 8), loadString(sp + 16), loadValue(sp + 32));\n },\n\n // func valueDelete(v ref, p string)\n \"syscall/js.valueDelete\": (sp) => {\n sp >>>= 0;\n Reflect.deleteProperty(loadValue(sp + 8), loadString(sp + 16));\n },\n\n // func valueIndex(v ref, i int) ref\n \"syscall/js.valueIndex\": (sp) => {\n sp >>>= 0;\n storeValue(sp + 24, Reflect.get(loadValue(sp + 8), getInt64(sp + 16)));\n },\n\n // valueSetIndex(v ref, i int, x ref)\n \"syscall/js.valueSetIndex\": (sp) => {\n sp >>>= 0;\n Reflect.set(loadValue(sp + 8), getInt64(sp + 16), loadValue(sp + 24));\n },\n\n // func valueCall(v ref, m string, args []ref) (ref, bool)\n \"syscall/js.valueCall\": (sp) => {\n sp >>>= 0;\n try {\n const v = loadValue(sp + 8);\n const m = Reflect.get(v, loadString(sp + 16));\n const args = loadSliceOfValues(sp + 32);\n const result = Reflect.apply(m, v, args);\n sp = this._inst.exports.getsp() >>> 0; // see comment above\n storeValue(sp + 56, result);\n this.mem.setUint8(sp + 64, 1);\n } catch (err) {\n sp = this._inst.exports.getsp() >>> 0; // see comment above\n storeValue(sp + 56, err);\n this.mem.setUint8(sp + 64, 0);\n }\n },\n\n // func valueInvoke(v ref, args []ref) (ref, bool)\n \"syscall/js.valueInvoke\": (sp) => {\n sp >>>= 0;\n try {\n const v = loadValue(sp + 8);\n const args = loadSliceOfValues(sp + 16);\n const result = Reflect.apply(v, undefined, args);\n sp = this._inst.exports.getsp() >>> 0; // see comment above\n storeValue(sp + 40, result);\n this.mem.setUint8(sp + 48, 1);\n } catch (err) {\n sp = this._inst.exports.getsp() >>> 0; // see comment above\n storeValue(sp + 40, err);\n this.mem.setUint8(sp + 48, 0);\n }\n },\n\n // func valueNew(v ref, args []ref) (ref, bool)\n \"syscall/js.valueNew\": (sp) => {\n sp >>>= 0;\n try {\n const v = loadValue(sp + 8);\n const args = loadSliceOfValues(sp + 16);\n const result = Reflect.construct(v, args);\n sp = this._inst.exports.getsp() >>> 0; // see comment above\n storeValue(sp + 40, result);\n this.mem.setUint8(sp + 48, 1);\n } catch (err) {\n sp = this._inst.exports.getsp() >>> 0; // see comment above\n storeValue(sp + 40, err);\n this.mem.setUint8(sp + 48, 0);\n }\n },\n\n // func valueLength(v ref) int\n \"syscall/js.valueLength\": (sp) => {\n sp >>>= 0;\n setInt64(sp + 16, parseInt(loadValue(sp + 8).length));\n },\n\n // valuePrepareString(v ref) (ref, int)\n \"syscall/js.valuePrepareString\": (sp) => {\n sp >>>= 0;\n const str = encoder.encode(String(loadValue(sp + 8)));\n storeValue(sp + 16, str);\n setInt64(sp + 24, str.length);\n },\n\n // valueLoadString(v ref, b []byte)\n \"syscall/js.valueLoadString\": (sp) => {\n sp >>>= 0;\n const str = loadValue(sp + 8);\n loadSlice(sp + 16).set(str);\n },\n\n // func valueInstanceOf(v ref, t ref) bool\n \"syscall/js.valueInstanceOf\": (sp) => {\n sp >>>= 0;\n this.mem.setUint8(sp + 24, loadValue(sp + 8) instanceof loadValue(sp + 16) ? 1 : 0);\n },\n\n // func copyBytesToGo(dst []byte, src ref) (int, bool)\n \"syscall/js.copyBytesToGo\": (sp) => {\n sp >>>= 0;\n const dst = loadSlice(sp + 8);\n const src = loadValue(sp + 32);\n if (!(src instanceof Uint8Array || src instanceof Uint8ClampedArray)) {\n this.mem.setUint8(sp + 48, 0);\n return;\n }\n const toCopy = src.subarray(0, dst.length);\n dst.set(toCopy);\n setInt64(sp + 40, toCopy.length);\n this.mem.setUint8(sp + 48, 1);\n },\n\n // func copyBytesToJS(dst ref, src []byte) (int, bool)\n \"syscall/js.copyBytesToJS\": (sp) => {\n sp >>>= 0;\n const dst = loadValue(sp + 8);\n const src = loadSlice(sp + 16);\n if (!(dst instanceof Uint8Array || dst instanceof Uint8ClampedArray)) {\n this.mem.setUint8(sp + 48, 0);\n return;\n }\n const toCopy = src.subarray(0, dst.length);\n dst.set(toCopy);\n setInt64(sp + 40, toCopy.length);\n this.mem.setUint8(sp + 48, 1);\n },\n\n debug: (value) => {\n console.log(value);\n },\n },\n };\n }\n\n async run(instance) {\n if (!(instance instanceof WebAssembly.Instance)) {\n throw new Error(\"Go.run: WebAssembly.Instance expected\");\n }\n this._inst = instance;\n this.mem = new DataView(this._inst.exports.mem.buffer);\n this._values = [\n // JS values that Go currently has references to, indexed by reference id\n NaN,\n 0,\n null,\n true,\n false,\n globalThis,\n this,\n ];\n this._goRefCounts = new Array(this._values.length).fill(Infinity); // number of references that Go has to a JS value, indexed by reference id\n this._ids = new Map([\n // mapping from JS values to reference ids\n [0, 1],\n [null, 2],\n [true, 3],\n [false, 4],\n [globalThis, 5],\n [this, 6],\n ]);\n this._idPool = []; // unused ids that have been garbage collected\n this.exited = false; // whether the Go program has exited\n\n // Pass command line arguments and environment variables to WebAssembly by writing them to the linear memory.\n let offset = 4096;\n\n const strPtr = (str) => {\n const ptr = offset;\n const bytes = encoder.encode(str + \"\\0\");\n new Uint8Array(this.mem.buffer, offset, bytes.length).set(bytes);\n offset += bytes.length;\n if (offset % 8 !== 0) {\n offset += 8 - (offset % 8);\n }\n return ptr;\n };\n\n const argc = this.argv.length;\n\n const argvPtrs = [];\n this.argv.forEach((arg) => {\n argvPtrs.push(strPtr(arg));\n });\n argvPtrs.push(0);\n\n const keys = Object.keys(this.env).sort();\n keys.forEach((key) => {\n argvPtrs.push(strPtr(`${key}=${this.env[key]}`));\n });\n argvPtrs.push(0);\n\n const argv = offset;\n argvPtrs.forEach((ptr) => {\n this.mem.setUint32(offset, ptr, true);\n this.mem.setUint32(offset + 4, 0, true);\n offset += 8;\n });\n\n // The linker guarantees global data starts from at least wasmMinDataAddr.\n // Keep in sync with cmd/link/internal/ld/data.go:wasmMinDataAddr.\n const wasmMinDataAddr = 4096 + 8192;\n if (offset >= wasmMinDataAddr) {\n throw new Error(\"total length of command line and environment variables exceeds limit\");\n }\n\n this._inst.exports.run(argc, argv);\n if (this.exited) {\n this._resolveExitPromise();\n }\n await this._exitPromise;\n }\n\n _resume() {\n if (this.exited) {\n throw new Error(\"Go program has already exited\");\n }\n this._inst.exports.resume();\n if (this.exited) {\n this._resolveExitPromise();\n }\n }\n\n _makeFuncWrapper(id) {\n const go = this;\n return function () {\n const event = { id: id, this: this, args: arguments };\n go._pendingEvent = event;\n go._resume();\n return event.result;\n };\n }\n}\n"],"names":["enosys","err","outputBuf","decoder","buf","nl","offset","length","position","callback","n","fd","encoder","Go","code","resolve","setInt64","addr","v","getInt64","low","high","loadValue","f","id","storeValue","nanHead","typeFlag","loadSlice","array","len","loadSliceOfValues","i","loadString","saddr","testCallExport","a","b","timeOrigin","sp","p","msec","result","m","args","str","dst","src","toCopy","value","instance","strPtr","ptr","bytes","argc","argvPtrs","arg","keys","key","argv","wasmMinDataAddr","go","event"],"mappings":"AAAA,MAAMA,MAAe,CACnB,IAAMC,EAAU,MAAM,mBAEtB,MADA,GAAI,KAAO,SACJA,GAGT,GAAI,CAAC,WAAW,GAAI,CAClB,IAAIC,EAAY,GAChB,WAAW,GAAK,CACd,UAAW,CACT,SAAU,GACV,OAAQ,GACR,QAAS,GACT,QAAS,GACT,SAAU,GACV,OAAQ,GACR,YAAa,IAEf,UAAU,EAAI,EAAK,CACjB,GAAaC,EAAQ,OAAOC,GAC5B,IAAMC,EAAKH,EAAU,YAAY;GAKjC,OAJIG,GAAM,KACR,QAAQ,IAAIH,EAAU,UAAU,EAA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M,KAAM,KAAM,WAG1C,MAFA,GAAG,cAAgBA,EACnBD,EAAG,UACIC,EAAM"}
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2025 startracex
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
package/index.js
DELETED
package/index.ts
DELETED
package/module-resolver.d.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { SubpathResolver } from "./subpath-resolver.js";
|
|
2
|
-
import { Specifier } from "./specifier.js";
|
|
3
|
-
export declare class ModuleResolver extends SubpathResolver {
|
|
4
|
-
extensions?: string[];
|
|
5
|
-
modulesDirectoryName: string;
|
|
6
|
-
manifestFileName: string;
|
|
7
|
-
mainFields: string[];
|
|
8
|
-
isCoreModule: (id: string) => boolean;
|
|
9
|
-
path: {
|
|
10
|
-
dirname: (path: string) => string;
|
|
11
|
-
join: (...paths: string[]) => string;
|
|
12
|
-
};
|
|
13
|
-
fs: {
|
|
14
|
-
statSync: (path: string) => {
|
|
15
|
-
isFile: () => boolean;
|
|
16
|
-
isDirectory: () => boolean;
|
|
17
|
-
};
|
|
18
|
-
readFileSync: (path: string) => string | {};
|
|
19
|
-
};
|
|
20
|
-
index: string;
|
|
21
|
-
constructor({ extensions, isCoreModule, modulesDirectoryName, manifestFileName, mainFields, index, path, fs, ...args }?: Partial<ModuleResolver>);
|
|
22
|
-
modulesPaths(start?: string, name?: string): string[];
|
|
23
|
-
resolve(path: string, base: string): string | undefined;
|
|
24
|
-
resolveModuleSpecifier({ name, path }: Specifier, base?: string): string | undefined;
|
|
25
|
-
protected resolveFile(filePath: string): string | undefined;
|
|
26
|
-
protected resolveDir(dirPath: string, entry?: string): string | undefined;
|
|
27
|
-
protected resolveFileOrDir(subPath: string, entry?: string): string | undefined;
|
|
28
|
-
protected readJSON(fullPath: string): Record<string, any>;
|
|
29
|
-
protected stat(path: string): {
|
|
30
|
-
isFile(): boolean;
|
|
31
|
-
isDirectory(): boolean;
|
|
32
|
-
} | null;
|
|
33
|
-
}
|
|
34
|
-
//# sourceMappingURL=module-resolver.d.ts.map
|
package/module-resolver.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"module-resolver.d.ts","sourceRoot":"","sources":["module-resolver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAkB,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAE3D,qBAAa,cAAe,SAAQ,eAAe;IACjD,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB,oBAAoB,EAAE,MAAM,CAAC;IAC7B,gBAAgB,EAAE,MAAM,CAAC;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,MAAM,GAAG,SAAS;IAIrB,SAAS,CAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;IAIzD,SAAS,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG;QAC5B,MAAM,IAAI,OAAO,CAAC;QAClB,WAAW,IAAI,OAAO,CAAC;KACxB,GAAG,IAAI;CAOT"}
|
package/module-resolver.js
DELETED
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
import { SubpathResolver } from "./subpath-resolver.js";
|
|
2
|
-
import { parseSpecifier } from "./specifier.js";
|
|
3
|
-
export class ModuleResolver extends SubpathResolver {
|
|
4
|
-
extensions;
|
|
5
|
-
modulesDirectoryName;
|
|
6
|
-
manifestFileName;
|
|
7
|
-
mainFields;
|
|
8
|
-
isCoreModule;
|
|
9
|
-
path;
|
|
10
|
-
fs;
|
|
11
|
-
index;
|
|
12
|
-
constructor({ extensions, isCoreModule = () => false, modulesDirectoryName = "node_modules", manifestFileName = "package.json", mainFields = ["main"], index = "index", path, fs, ...args } = {}) {
|
|
13
|
-
super(args);
|
|
14
|
-
this.extensions = extensions;
|
|
15
|
-
this.isCoreModule = isCoreModule;
|
|
16
|
-
this.modulesDirectoryName = modulesDirectoryName;
|
|
17
|
-
this.manifestFileName = manifestFileName;
|
|
18
|
-
this.mainFields = mainFields;
|
|
19
|
-
this.path = path;
|
|
20
|
-
this.fs = fs;
|
|
21
|
-
this.index = index;
|
|
22
|
-
}
|
|
23
|
-
modulesPaths(start, name = "") {
|
|
24
|
-
const paths = [];
|
|
25
|
-
if (!start) {
|
|
26
|
-
return paths;
|
|
27
|
-
}
|
|
28
|
-
for (;;) {
|
|
29
|
-
paths.push(this.path.join(start, this.modulesDirectoryName, name));
|
|
30
|
-
const parent = this.path.dirname(start);
|
|
31
|
-
if (parent === start) {
|
|
32
|
-
break;
|
|
33
|
-
}
|
|
34
|
-
start = parent;
|
|
35
|
-
}
|
|
36
|
-
return paths;
|
|
37
|
-
}
|
|
38
|
-
resolve(path, base) {
|
|
39
|
-
if (this.isCoreModule?.(path)) {
|
|
40
|
-
return path;
|
|
41
|
-
}
|
|
42
|
-
if (path.startsWith("#")) {
|
|
43
|
-
const paths = this.resolveImports(path);
|
|
44
|
-
if (paths) {
|
|
45
|
-
for (const p of paths) {
|
|
46
|
-
const rd = this.resolveFileOrDir(p);
|
|
47
|
-
if (rd) {
|
|
48
|
-
return rd;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
const spec = parseSpecifier(path);
|
|
55
|
-
if (spec?.name) {
|
|
56
|
-
return this.resolveModuleSpecifier(spec, base);
|
|
57
|
-
}
|
|
58
|
-
return this.resolveFileOrDir(this.path.join(base, path));
|
|
59
|
-
}
|
|
60
|
-
resolveModuleSpecifier({ name, path }, base) {
|
|
61
|
-
const dirs = this.modulesPaths(base, name);
|
|
62
|
-
for (const dir of dirs) {
|
|
63
|
-
const stat = this.stat(dir);
|
|
64
|
-
if (stat?.isDirectory()) {
|
|
65
|
-
const rd = this.resolveDir(dir, path);
|
|
66
|
-
if (rd) {
|
|
67
|
-
return rd;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
resolveFile(filePath) {
|
|
73
|
-
const candidates = [
|
|
74
|
-
filePath,
|
|
75
|
-
...(this.extensions || []).map((ext) => filePath + ext),
|
|
76
|
-
];
|
|
77
|
-
for (const file of candidates) {
|
|
78
|
-
const stat = this.stat(file);
|
|
79
|
-
if (!stat || stat.isDirectory()) {
|
|
80
|
-
continue;
|
|
81
|
-
}
|
|
82
|
-
if (stat.isFile()) {
|
|
83
|
-
return file;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
resolveDir(dirPath, entry) {
|
|
88
|
-
const packageJsonPath = this.path.join(dirPath, this.manifestFileName);
|
|
89
|
-
const stat = this.stat(packageJsonPath);
|
|
90
|
-
if (!stat?.isFile()) {
|
|
91
|
-
return this.resolveFile(this.path.join(dirPath, this.index));
|
|
92
|
-
}
|
|
93
|
-
const pkg = this.readJSON(packageJsonPath);
|
|
94
|
-
if (pkg.exports) {
|
|
95
|
-
const exportsMatchArray = new SubpathResolver({
|
|
96
|
-
exports: pkg.exports,
|
|
97
|
-
conditions: this.conditions,
|
|
98
|
-
}).resolveExports(entry);
|
|
99
|
-
if (exportsMatchArray) {
|
|
100
|
-
for (let match of exportsMatchArray) {
|
|
101
|
-
match = this.path.join(dirPath, match);
|
|
102
|
-
const stat = this.stat(match);
|
|
103
|
-
if (stat?.isFile()) {
|
|
104
|
-
return match;
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
|
-
if (!entry) {
|
|
111
|
-
for (const field of this.mainFields) {
|
|
112
|
-
let main = pkg[field];
|
|
113
|
-
if (!main) {
|
|
114
|
-
continue;
|
|
115
|
-
}
|
|
116
|
-
main = this.path.join(dirPath, main);
|
|
117
|
-
const stat = this.stat(main);
|
|
118
|
-
if (stat?.isFile()) {
|
|
119
|
-
return main;
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
return;
|
|
123
|
-
}
|
|
124
|
-
const subPath = this.path.join(dirPath, entry);
|
|
125
|
-
return this.resolveFileOrDir(subPath);
|
|
126
|
-
}
|
|
127
|
-
resolveFileOrDir(subPath, entry) {
|
|
128
|
-
return this.resolveFile(subPath) || this.resolveDir(subPath, entry);
|
|
129
|
-
}
|
|
130
|
-
readJSON(fullPath) {
|
|
131
|
-
return JSON.parse(this.fs.readFileSync(fullPath).toString());
|
|
132
|
-
}
|
|
133
|
-
stat(path) {
|
|
134
|
-
try {
|
|
135
|
-
return this.fs.statSync(path);
|
|
136
|
-
}
|
|
137
|
-
catch (e) {
|
|
138
|
-
return null;
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
}
|
package/module-resolver.ts
DELETED
|
@@ -1,186 +0,0 @@
|
|
|
1
|
-
import { SubpathResolver } from "./subpath-resolver.js";
|
|
2
|
-
import { parseSpecifier, Specifier } from "./specifier.js";
|
|
3
|
-
|
|
4
|
-
export class ModuleResolver extends SubpathResolver {
|
|
5
|
-
extensions?: string[];
|
|
6
|
-
modulesDirectoryName: string;
|
|
7
|
-
manifestFileName: string;
|
|
8
|
-
mainFields: string[];
|
|
9
|
-
isCoreModule: (id: string) => boolean;
|
|
10
|
-
path: {
|
|
11
|
-
dirname: (path: string) => string;
|
|
12
|
-
join: (...paths: string[]) => string;
|
|
13
|
-
};
|
|
14
|
-
fs: {
|
|
15
|
-
statSync: (path: string) => {
|
|
16
|
-
isFile: () => boolean;
|
|
17
|
-
isDirectory: () => boolean;
|
|
18
|
-
};
|
|
19
|
-
readFileSync: (path: string) => string | {};
|
|
20
|
-
};
|
|
21
|
-
index: string;
|
|
22
|
-
|
|
23
|
-
constructor({
|
|
24
|
-
extensions,
|
|
25
|
-
isCoreModule = () => false,
|
|
26
|
-
modulesDirectoryName = "node_modules",
|
|
27
|
-
manifestFileName = "package.json",
|
|
28
|
-
mainFields = ["main"],
|
|
29
|
-
index = "index",
|
|
30
|
-
path,
|
|
31
|
-
fs,
|
|
32
|
-
...args
|
|
33
|
-
}: Partial<ModuleResolver> = {}) {
|
|
34
|
-
super(args);
|
|
35
|
-
this.extensions = extensions;
|
|
36
|
-
this.isCoreModule = isCoreModule;
|
|
37
|
-
this.modulesDirectoryName = modulesDirectoryName;
|
|
38
|
-
this.manifestFileName = manifestFileName;
|
|
39
|
-
this.mainFields = mainFields;
|
|
40
|
-
this.path = path;
|
|
41
|
-
this.fs = fs;
|
|
42
|
-
this.index = index;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
modulesPaths(start?: string, name = ""): string[] {
|
|
46
|
-
const paths: string[] = [];
|
|
47
|
-
|
|
48
|
-
if (!start) {
|
|
49
|
-
return paths;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
for (;;) {
|
|
53
|
-
paths.push(this.path.join(start, this.modulesDirectoryName, name));
|
|
54
|
-
const parent = this.path.dirname(start);
|
|
55
|
-
if (parent === start) {
|
|
56
|
-
break;
|
|
57
|
-
}
|
|
58
|
-
start = parent;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
return paths;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
resolve(path: string, base: string): string | undefined {
|
|
65
|
-
if (this.isCoreModule?.(path)) {
|
|
66
|
-
return path;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
if (path.startsWith("#")) {
|
|
70
|
-
const paths = this.resolveImports(path);
|
|
71
|
-
if (paths) {
|
|
72
|
-
for (const p of paths) {
|
|
73
|
-
const rd = this.resolveFileOrDir(p);
|
|
74
|
-
if (rd) {
|
|
75
|
-
return rd;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
const spec = parseSpecifier(path);
|
|
83
|
-
|
|
84
|
-
if (spec?.name) {
|
|
85
|
-
return this.resolveModuleSpecifier(spec, base);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
return this.resolveFileOrDir(this.path.join(base, path));
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
resolveModuleSpecifier(
|
|
92
|
-
{ name, path }: Specifier,
|
|
93
|
-
base?: string,
|
|
94
|
-
): string | undefined {
|
|
95
|
-
const dirs = this.modulesPaths(base, name);
|
|
96
|
-
for (const dir of dirs) {
|
|
97
|
-
const stat = this.stat(dir);
|
|
98
|
-
if (stat?.isDirectory()) {
|
|
99
|
-
const rd = this.resolveDir(dir, path);
|
|
100
|
-
if (rd) {
|
|
101
|
-
return rd;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
protected resolveFile(filePath: string): string | undefined {
|
|
108
|
-
const candidates = [
|
|
109
|
-
filePath,
|
|
110
|
-
...(this.extensions || []).map((ext) => filePath + ext),
|
|
111
|
-
];
|
|
112
|
-
for (const file of candidates) {
|
|
113
|
-
const stat = this.stat(file);
|
|
114
|
-
if (!stat || stat.isDirectory()) {
|
|
115
|
-
continue;
|
|
116
|
-
}
|
|
117
|
-
if (stat.isFile()) {
|
|
118
|
-
return file;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
protected resolveDir(dirPath: string, entry?: string): string | undefined {
|
|
124
|
-
const packageJsonPath = this.path.join(dirPath, this.manifestFileName);
|
|
125
|
-
const stat = this.stat(packageJsonPath);
|
|
126
|
-
if (!stat?.isFile()) {
|
|
127
|
-
return this.resolveFile(this.path.join(dirPath, this.index));
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
const pkg = this.readJSON(packageJsonPath);
|
|
131
|
-
if (pkg.exports) {
|
|
132
|
-
const exportsMatchArray = new SubpathResolver({
|
|
133
|
-
exports: pkg.exports,
|
|
134
|
-
conditions: this.conditions,
|
|
135
|
-
}).resolveExports(entry);
|
|
136
|
-
if (exportsMatchArray) {
|
|
137
|
-
for (let match of exportsMatchArray) {
|
|
138
|
-
match = this.path.join(dirPath, match);
|
|
139
|
-
const stat = this.stat(match);
|
|
140
|
-
if (stat?.isFile()) {
|
|
141
|
-
return match;
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
return;
|
|
146
|
-
}
|
|
147
|
-
if (!entry) {
|
|
148
|
-
for (const field of this.mainFields) {
|
|
149
|
-
let main = pkg[field];
|
|
150
|
-
if (!main) {
|
|
151
|
-
continue;
|
|
152
|
-
}
|
|
153
|
-
main = this.path.join(dirPath, main);
|
|
154
|
-
const stat = this.stat(main);
|
|
155
|
-
if (stat?.isFile()) {
|
|
156
|
-
return main;
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
return;
|
|
160
|
-
}
|
|
161
|
-
const subPath = this.path.join(dirPath, entry);
|
|
162
|
-
return this.resolveFileOrDir(subPath);
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
protected resolveFileOrDir(
|
|
166
|
-
subPath: string,
|
|
167
|
-
entry?: string,
|
|
168
|
-
): string | undefined {
|
|
169
|
-
return this.resolveFile(subPath) || this.resolveDir(subPath, entry);
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
protected readJSON(fullPath: string): Record<string, any> {
|
|
173
|
-
return JSON.parse(this.fs.readFileSync(fullPath).toString());
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
protected stat(path: string): {
|
|
177
|
-
isFile(): boolean;
|
|
178
|
-
isDirectory(): boolean;
|
|
179
|
-
} | null {
|
|
180
|
-
try {
|
|
181
|
-
return this.fs.statSync(path);
|
|
182
|
-
} catch (e) {
|
|
183
|
-
return null;
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
}
|
package/specifier.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export type Specifier = {
|
|
2
|
-
proto?: string;
|
|
3
|
-
scope?: string;
|
|
4
|
-
pkg?: string;
|
|
5
|
-
name?: string;
|
|
6
|
-
path?: string;
|
|
7
|
-
};
|
|
8
|
-
/**
|
|
9
|
-
* Parse a input string into a Specifier.
|
|
10
|
-
*
|
|
11
|
-
* input can be a npm package name with optional proto, subpath.
|
|
12
|
-
*/
|
|
13
|
-
export declare const parseSpecifier: (input: string) => Specifier | null;
|
|
14
|
-
//# sourceMappingURL=specifier.d.ts.map
|
package/specifier.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"specifier.d.ts","sourceRoot":"","sources":["specifier.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,GAAG;IACtB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AAIF;;;;GAIG;AACH,eAAO,MAAM,cAAc,GAAI,OAAO,MAAM,KAAG,SAAS,GAAG,IAwB1D,CAAC"}
|
package/specifier.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
const regexp = /^(?:@(\w[\w-.]*)\/)?(\w[\w-.]*)(\/(.*))?/;
|
|
2
|
-
/**
|
|
3
|
-
* Parse a input string into a Specifier.
|
|
4
|
-
*
|
|
5
|
-
* input can be a npm package name with optional proto, subpath.
|
|
6
|
-
*/
|
|
7
|
-
export const parseSpecifier = (input) => {
|
|
8
|
-
if (!input) {
|
|
9
|
-
return null;
|
|
10
|
-
}
|
|
11
|
-
const sp = input.split(":");
|
|
12
|
-
const path = sp.pop();
|
|
13
|
-
const match = path.match(regexp);
|
|
14
|
-
console.log(match);
|
|
15
|
-
if (!match || !match[0] || !match[2]) {
|
|
16
|
-
return null;
|
|
17
|
-
}
|
|
18
|
-
const scope = match[1];
|
|
19
|
-
const pkg = match[2];
|
|
20
|
-
const result = {
|
|
21
|
-
name: scope ? `@${scope}/${pkg}` : pkg,
|
|
22
|
-
scope,
|
|
23
|
-
pkg,
|
|
24
|
-
proto: sp.pop(),
|
|
25
|
-
path: match[4],
|
|
26
|
-
};
|
|
27
|
-
return result;
|
|
28
|
-
};
|
package/specifier.ts
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
export type Specifier = {
|
|
2
|
-
proto?: string;
|
|
3
|
-
scope?: string;
|
|
4
|
-
pkg?: string;
|
|
5
|
-
name?: string;
|
|
6
|
-
path?: string;
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
const regexp = /^(?:@(\w[\w-.]*)\/)?(\w[\w-.]*)(\/(.*))?/;
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Parse a input string into a Specifier.
|
|
13
|
-
*
|
|
14
|
-
* input can be a npm package name with optional proto, subpath.
|
|
15
|
-
*/
|
|
16
|
-
export const parseSpecifier = (input: string): Specifier | null => {
|
|
17
|
-
if (!input) {
|
|
18
|
-
return null;
|
|
19
|
-
}
|
|
20
|
-
const sp = input.split(":");
|
|
21
|
-
const path = sp.pop();
|
|
22
|
-
|
|
23
|
-
const match = path.match(regexp);
|
|
24
|
-
|
|
25
|
-
console.log(match);
|
|
26
|
-
if (!match || !match[0] || !match[2]) {
|
|
27
|
-
return null;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const scope = match[1];
|
|
31
|
-
const pkg = match[2];
|
|
32
|
-
const result: Specifier = {
|
|
33
|
-
name: scope ? `@${scope}/${pkg}` : pkg,
|
|
34
|
-
scope,
|
|
35
|
-
pkg,
|
|
36
|
-
proto: sp.pop(),
|
|
37
|
-
path: match[4],
|
|
38
|
-
};
|
|
39
|
-
return result;
|
|
40
|
-
};
|
package/subpath-resolver.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
type Value = string | string[] | {
|
|
2
|
-
[key: string]: Value;
|
|
3
|
-
};
|
|
4
|
-
export declare const resolveMapping: (mapping: Record<string, Value>, conditions: string[], input: string) => string[] | null;
|
|
5
|
-
export declare class SubpathResolver {
|
|
6
|
-
conditions: string[];
|
|
7
|
-
exports: Record<string, Value>;
|
|
8
|
-
imports: Record<string, Value>;
|
|
9
|
-
constructor({ exports, imports, conditions, }: {
|
|
10
|
-
exports?: Value;
|
|
11
|
-
imports?: Record<string, Value>;
|
|
12
|
-
conditions?: string[];
|
|
13
|
-
});
|
|
14
|
-
resolveExports(entry?: string): string[];
|
|
15
|
-
resolveImports(entry: string): string[] | null;
|
|
16
|
-
}
|
|
17
|
-
export {};
|
|
18
|
-
//# sourceMappingURL=subpath-resolver.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"subpath-resolver.d.ts","sourceRoot":"","sources":["subpath-resolver.ts"],"names":[],"mappings":"AAAA,KAAK,KAAK,GAAG,MAAM,GAAG,MAAM,EAAE,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,KAAK,CAAA;CAAE,CAAC;AAyE1D,eAAO,MAAM,cAAc,GACzB,SAAS,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,EAC9B,YAAY,MAAM,EAAE,EACpB,OAAO,MAAM,KACZ,MAAM,EAAE,GAAG,IA6Bb,CAAC;AAcF,qBAAa,eAAe;IAC1B,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IAC/B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;gBAEnB,EACV,OAAO,EACP,OAAO,EACP,UAAwB,GACzB,EAAE;QACD,OAAO,CAAC,EAAE,KAAK,CAAC;QAChB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;QAChC,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;KACvB;IAMD,cAAc,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE;IAIxC,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,IAAI;CAM/C"}
|
package/subpath-resolver.js
DELETED
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
const normalizeMapping = (m) => {
|
|
2
|
-
if (!m) {
|
|
3
|
-
return {};
|
|
4
|
-
}
|
|
5
|
-
if (typeof m === "string" || Array.isArray(m)) {
|
|
6
|
-
return { ".": m };
|
|
7
|
-
}
|
|
8
|
-
return m;
|
|
9
|
-
};
|
|
10
|
-
const findWildcardMatch = (mapping, input) => {
|
|
11
|
-
let bestMatch = null;
|
|
12
|
-
let replacement = "";
|
|
13
|
-
for (const key in mapping) {
|
|
14
|
-
if (key.endsWith("/*")) {
|
|
15
|
-
const prefix = key.slice(0, -1);
|
|
16
|
-
if (input.startsWith(prefix)) {
|
|
17
|
-
const matchLength = prefix.length;
|
|
18
|
-
if (!bestMatch || matchLength > bestMatch.length) {
|
|
19
|
-
bestMatch = { key, length: matchLength };
|
|
20
|
-
replacement = input.slice(prefix.length);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
else if (key.includes("*")) {
|
|
25
|
-
const [before, after] = key.split("*");
|
|
26
|
-
if (input.startsWith(before) && input.endsWith(after)) {
|
|
27
|
-
const matchLength = before.length + after.length;
|
|
28
|
-
if (!bestMatch || matchLength > bestMatch.length) {
|
|
29
|
-
bestMatch = { key, length: matchLength };
|
|
30
|
-
replacement = input.slice(before.length, input.length - after.length);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
else if (key.endsWith("/") && input.startsWith(key)) {
|
|
35
|
-
const matchLength = key.length;
|
|
36
|
-
if (!bestMatch || matchLength > bestMatch.length) {
|
|
37
|
-
bestMatch = { key, length: matchLength };
|
|
38
|
-
replacement = input.slice(key.length);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
return bestMatch ? { key: bestMatch.key, replacement } : null;
|
|
43
|
-
};
|
|
44
|
-
const resolveMappingValue = (value, conditions) => {
|
|
45
|
-
if (!value)
|
|
46
|
-
return null;
|
|
47
|
-
if (typeof value === "string") {
|
|
48
|
-
return [value];
|
|
49
|
-
}
|
|
50
|
-
if (Array.isArray(value)) {
|
|
51
|
-
return value.flatMap((v) => resolveMappingValue(v, conditions) || []);
|
|
52
|
-
}
|
|
53
|
-
for (const [condition, subValue] of Object.entries(value)) {
|
|
54
|
-
if (conditions.includes(condition)) {
|
|
55
|
-
return resolveMappingValue(subValue, conditions);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
return null;
|
|
59
|
-
};
|
|
60
|
-
export const resolveMapping = (mapping, conditions, input) => {
|
|
61
|
-
let value = mapping[input];
|
|
62
|
-
let wildcardMatch = null;
|
|
63
|
-
if (value === undefined) {
|
|
64
|
-
wildcardMatch = findWildcardMatch(mapping, input);
|
|
65
|
-
if (wildcardMatch) {
|
|
66
|
-
value = mapping[wildcardMatch.key];
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
const resolved = resolveMappingValue(value, conditions);
|
|
70
|
-
if (!resolved) {
|
|
71
|
-
return null;
|
|
72
|
-
}
|
|
73
|
-
if (!wildcardMatch) {
|
|
74
|
-
return resolved;
|
|
75
|
-
}
|
|
76
|
-
return resolved.map((r) => {
|
|
77
|
-
if (r.includes("*")) {
|
|
78
|
-
return r.replace("*", wildcardMatch.replacement);
|
|
79
|
-
}
|
|
80
|
-
if (r.endsWith("/")) {
|
|
81
|
-
return r + wildcardMatch.replacement;
|
|
82
|
-
}
|
|
83
|
-
return r;
|
|
84
|
-
});
|
|
85
|
-
};
|
|
86
|
-
const subpathPrefix = "./";
|
|
87
|
-
const normalizeEntry = (entry) => {
|
|
88
|
-
if (!entry || entry === "." || entry === subpathPrefix) {
|
|
89
|
-
return ".";
|
|
90
|
-
}
|
|
91
|
-
if (entry.startsWith(subpathPrefix)) {
|
|
92
|
-
return entry;
|
|
93
|
-
}
|
|
94
|
-
return subpathPrefix + entry;
|
|
95
|
-
};
|
|
96
|
-
export class SubpathResolver {
|
|
97
|
-
conditions;
|
|
98
|
-
exports;
|
|
99
|
-
imports;
|
|
100
|
-
constructor({ exports, imports, conditions = ["default"], }) {
|
|
101
|
-
this.imports = imports;
|
|
102
|
-
this.exports = normalizeMapping(exports);
|
|
103
|
-
this.conditions = conditions;
|
|
104
|
-
}
|
|
105
|
-
resolveExports(entry) {
|
|
106
|
-
return resolveMapping(this.exports, this.conditions, normalizeEntry(entry));
|
|
107
|
-
}
|
|
108
|
-
resolveImports(entry) {
|
|
109
|
-
if (!this.imports) {
|
|
110
|
-
return null;
|
|
111
|
-
}
|
|
112
|
-
return resolveMapping(this.imports, this.conditions, entry);
|
|
113
|
-
}
|
|
114
|
-
}
|
package/subpath-resolver.ts
DELETED
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
type Value = string | string[] | { [key: string]: Value };
|
|
2
|
-
|
|
3
|
-
const normalizeMapping = (m: Value): Record<string, Value> => {
|
|
4
|
-
if (!m) {
|
|
5
|
-
return {};
|
|
6
|
-
}
|
|
7
|
-
if (typeof m === "string" || Array.isArray(m)) {
|
|
8
|
-
return { ".": m };
|
|
9
|
-
}
|
|
10
|
-
return m;
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
const findWildcardMatch = (
|
|
14
|
-
mapping: Record<string, Value>,
|
|
15
|
-
input: string,
|
|
16
|
-
): { key: string; replacement: string } | null => {
|
|
17
|
-
let bestMatch: { key: string; length: number } | null = null;
|
|
18
|
-
let replacement = "";
|
|
19
|
-
|
|
20
|
-
for (const key in mapping) {
|
|
21
|
-
if (key.endsWith("/*")) {
|
|
22
|
-
const prefix = key.slice(0, -1);
|
|
23
|
-
if (input.startsWith(prefix)) {
|
|
24
|
-
const matchLength = prefix.length;
|
|
25
|
-
if (!bestMatch || matchLength > bestMatch.length) {
|
|
26
|
-
bestMatch = { key, length: matchLength };
|
|
27
|
-
replacement = input.slice(prefix.length);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
} else if (key.includes("*")) {
|
|
31
|
-
const [before, after] = key.split("*");
|
|
32
|
-
if (input.startsWith(before) && input.endsWith(after)) {
|
|
33
|
-
const matchLength = before.length + after.length;
|
|
34
|
-
if (!bestMatch || matchLength > bestMatch.length) {
|
|
35
|
-
bestMatch = { key, length: matchLength };
|
|
36
|
-
replacement = input.slice(before.length, input.length - after.length);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
} else if (key.endsWith("/") && input.startsWith(key)) {
|
|
40
|
-
const matchLength = key.length;
|
|
41
|
-
if (!bestMatch || matchLength > bestMatch.length) {
|
|
42
|
-
bestMatch = { key, length: matchLength };
|
|
43
|
-
replacement = input.slice(key.length);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
return bestMatch ? { key: bestMatch.key, replacement } : null;
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
const resolveMappingValue = (
|
|
52
|
-
value: Value | undefined,
|
|
53
|
-
conditions: string[],
|
|
54
|
-
): string[] | null => {
|
|
55
|
-
if (!value) return null;
|
|
56
|
-
|
|
57
|
-
if (typeof value === "string") {
|
|
58
|
-
return [value];
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
if (Array.isArray(value)) {
|
|
62
|
-
return value.flatMap((v) => resolveMappingValue(v, conditions) || []);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
for (const [condition, subValue] of Object.entries(value)) {
|
|
66
|
-
if (conditions.includes(condition)) {
|
|
67
|
-
return resolveMappingValue(subValue, conditions);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
return null;
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
export const resolveMapping = (
|
|
75
|
-
mapping: Record<string, Value>,
|
|
76
|
-
conditions: string[],
|
|
77
|
-
input: string,
|
|
78
|
-
): string[] | null => {
|
|
79
|
-
let value = mapping[input];
|
|
80
|
-
let wildcardMatch: { key: string; replacement: string } | null = null;
|
|
81
|
-
|
|
82
|
-
if (value === undefined) {
|
|
83
|
-
wildcardMatch = findWildcardMatch(mapping, input);
|
|
84
|
-
if (wildcardMatch) {
|
|
85
|
-
value = mapping[wildcardMatch.key];
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
const resolved = resolveMappingValue(value, conditions);
|
|
90
|
-
if (!resolved) {
|
|
91
|
-
return null;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
if (!wildcardMatch) {
|
|
95
|
-
return resolved;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
return resolved.map((r) => {
|
|
99
|
-
if (r.includes("*")) {
|
|
100
|
-
return r.replace("*", wildcardMatch.replacement);
|
|
101
|
-
}
|
|
102
|
-
if (r.endsWith("/")) {
|
|
103
|
-
return r + wildcardMatch.replacement;
|
|
104
|
-
}
|
|
105
|
-
return r;
|
|
106
|
-
});
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
const subpathPrefix = "./";
|
|
110
|
-
|
|
111
|
-
const normalizeEntry = (entry: string) => {
|
|
112
|
-
if (!entry || entry === "." || entry === subpathPrefix) {
|
|
113
|
-
return ".";
|
|
114
|
-
}
|
|
115
|
-
if (entry.startsWith(subpathPrefix)) {
|
|
116
|
-
return entry;
|
|
117
|
-
}
|
|
118
|
-
return subpathPrefix + entry;
|
|
119
|
-
};
|
|
120
|
-
|
|
121
|
-
export class SubpathResolver {
|
|
122
|
-
conditions: string[];
|
|
123
|
-
exports: Record<string, Value>;
|
|
124
|
-
imports: Record<string, Value>;
|
|
125
|
-
|
|
126
|
-
constructor({
|
|
127
|
-
exports,
|
|
128
|
-
imports,
|
|
129
|
-
conditions = ["default"],
|
|
130
|
-
}: {
|
|
131
|
-
exports?: Value;
|
|
132
|
-
imports?: Record<string, Value>;
|
|
133
|
-
conditions?: string[];
|
|
134
|
-
}) {
|
|
135
|
-
this.imports = imports;
|
|
136
|
-
this.exports = normalizeMapping(exports);
|
|
137
|
-
this.conditions = conditions;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
resolveExports(entry?: string): string[] {
|
|
141
|
-
return resolveMapping(this.exports, this.conditions, normalizeEntry(entry));
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
resolveImports(entry: string): string[] | null {
|
|
145
|
-
if (!this.imports) {
|
|
146
|
-
return null;
|
|
147
|
-
}
|
|
148
|
-
return resolveMapping(this.imports, this.conditions, entry);
|
|
149
|
-
}
|
|
150
|
-
}
|