@ricsam/isolate 0.1.1 → 0.1.2
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.
|
@@ -77,8 +77,10 @@ class ModuleResolverBuilder {
|
|
|
77
77
|
virtualFiles = new Map;
|
|
78
78
|
sourceTrees = [];
|
|
79
79
|
fallbackLoader;
|
|
80
|
+
nodeModulesLoader;
|
|
80
81
|
mountNodeModules(virtualMount, hostPath) {
|
|
81
82
|
this.nodeModuleMappings.push({ from: hostPath, to: virtualMount });
|
|
83
|
+
this.nodeModulesLoader = undefined;
|
|
82
84
|
return this;
|
|
83
85
|
}
|
|
84
86
|
virtual(specifier, source, options) {
|
|
@@ -135,9 +137,8 @@ class ModuleResolverBuilder {
|
|
|
135
137
|
}
|
|
136
138
|
}
|
|
137
139
|
if (this.nodeModuleMappings.length > 0) {
|
|
138
|
-
const mappedLoader = import_module_loader.defaultModuleLoader(...this.nodeModuleMappings);
|
|
139
140
|
try {
|
|
140
|
-
return await
|
|
141
|
+
return await this.getNodeModulesLoader()(specifier, importer);
|
|
141
142
|
} catch (error) {
|
|
142
143
|
if (!this.fallbackLoader) {
|
|
143
144
|
throw error;
|
|
@@ -152,9 +153,15 @@ class ModuleResolverBuilder {
|
|
|
152
153
|
}
|
|
153
154
|
throw new Error(`Unable to resolve module: ${specifier}`);
|
|
154
155
|
}
|
|
156
|
+
getNodeModulesLoader() {
|
|
157
|
+
if (!this.nodeModulesLoader) {
|
|
158
|
+
this.nodeModulesLoader = import_module_loader.defaultModuleLoader(...this.nodeModuleMappings);
|
|
159
|
+
}
|
|
160
|
+
return this.nodeModulesLoader;
|
|
161
|
+
}
|
|
155
162
|
}
|
|
156
163
|
function createModuleResolver() {
|
|
157
164
|
return new ModuleResolverBuilder;
|
|
158
165
|
}
|
|
159
166
|
|
|
160
|
-
//# debugId=
|
|
167
|
+
//# debugId=363B95C4D202910564756E2164756E21
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/modules/index.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"import fs from \"node:fs\";\nimport path from \"node:path\";\nimport { defaultModuleLoader } from \"../internal/module-loader/index.cjs\";\nimport { normalizeExplicitModuleResult } from \"../bridge/legacy-adapters.cjs\";\nimport type { HostCallContext, ModuleResolveResult, ModuleResolver, ModuleResolverFallback, ModuleResolverSourceLoader, ModuleSource } from \"../types.cjs\";\n\nclass ModuleResolverBuilder implements ModuleResolver {\n private readonly nodeModuleMappings: Array<{ from: string; to: string }> = [];\n private readonly virtualEntries = new Map<string, { source: ModuleResolveResult | (() => ModuleResolveResult); options?: Partial<ModuleSource> }>();\n private readonly virtualFiles = new Map<string, { filePath: string; options?: Partial<ModuleSource> }>();\n private readonly sourceTrees: Array<{ prefix: string; loader: ModuleResolverSourceLoader }> = [];\n private fallbackLoader?: ModuleResolverFallback;\n\n mountNodeModules(virtualMount: string, hostPath: string): ModuleResolver {\n this.nodeModuleMappings.push({ from: hostPath, to: virtualMount });\n return this;\n }\n\n virtual(specifier: string, source: ModuleResolveResult | (() => ModuleResolveResult), options?: Partial<ModuleSource>): ModuleResolver {\n this.virtualEntries.set(specifier, { source, options });\n return this;\n }\n\n virtualFile(specifier: string, filePath: string, options?: Partial<ModuleSource>): ModuleResolver {\n this.virtualFiles.set(specifier, { filePath, options });\n return this;\n }\n\n sourceTree(prefix: string, loader: ModuleResolverSourceLoader): ModuleResolver {\n this.sourceTrees.push({ prefix, loader });\n return this;\n }\n\n fallback(loader: ModuleResolverFallback): ModuleResolver {\n this.fallbackLoader = loader;\n return this;\n }\n\n async resolve(specifier: string, importer: { path: string; resolveDir: string }, context: HostCallContext): Promise<ModuleSource> {\n const explicit = this.virtualEntries.get(specifier);\n if (explicit) {\n const raw = typeof explicit.source === \"function\" ? await explicit.source() : await explicit.source;\n const normalized = await normalizeExplicitModuleResult(specifier, raw, importer.resolveDir);\n if (!normalized) {\n throw new Error(`Virtual module ${specifier} returned no source.`);\n }\n return {\n ...normalized,\n ...explicit.options,\n };\n }\n\n const virtualFile = this.virtualFiles.get(specifier);\n if (virtualFile) {\n const code = fs.readFileSync(virtualFile.filePath, \"utf-8\");\n const fallback = await normalizeExplicitModuleResult(\n specifier,\n {\n code,\n filename: virtualFile.options?.filename ?? path.basename(virtualFile.filePath),\n resolveDir: virtualFile.options?.resolveDir ?? path.posix.dirname(specifier.startsWith(\"/\") ? specifier : `/${specifier}`),\n static: virtualFile.options?.static,\n },\n importer.resolveDir,\n );\n if (!fallback) {\n throw new Error(`Virtual file module ${specifier} returned no source.`);\n }\n return fallback;\n }\n\n for (const sourceTree of this.sourceTrees) {\n if (!specifier.startsWith(sourceTree.prefix)) {\n continue;\n }\n const relativePath = specifier.slice(sourceTree.prefix.length);\n const normalized = await normalizeExplicitModuleResult(specifier, sourceTree.loader(relativePath, context), importer.resolveDir);\n if (normalized) {\n return normalized;\n }\n }\n\n if (this.nodeModuleMappings.length > 0) {\n
|
|
5
|
+
"import fs from \"node:fs\";\nimport path from \"node:path\";\nimport { defaultModuleLoader } from \"../internal/module-loader/index.cjs\";\nimport { normalizeExplicitModuleResult } from \"../bridge/legacy-adapters.cjs\";\nimport type { HostCallContext, ModuleResolveResult, ModuleResolver, ModuleResolverFallback, ModuleResolverSourceLoader, ModuleSource } from \"../types.cjs\";\n\nclass ModuleResolverBuilder implements ModuleResolver {\n private readonly nodeModuleMappings: Array<{ from: string; to: string }> = [];\n private readonly virtualEntries = new Map<string, { source: ModuleResolveResult | (() => ModuleResolveResult); options?: Partial<ModuleSource> }>();\n private readonly virtualFiles = new Map<string, { filePath: string; options?: Partial<ModuleSource> }>();\n private readonly sourceTrees: Array<{ prefix: string; loader: ModuleResolverSourceLoader }> = [];\n private fallbackLoader?: ModuleResolverFallback;\n private nodeModulesLoader?: ReturnType<typeof defaultModuleLoader>;\n\n mountNodeModules(virtualMount: string, hostPath: string): ModuleResolver {\n this.nodeModuleMappings.push({ from: hostPath, to: virtualMount });\n this.nodeModulesLoader = undefined;\n return this;\n }\n\n virtual(specifier: string, source: ModuleResolveResult | (() => ModuleResolveResult), options?: Partial<ModuleSource>): ModuleResolver {\n this.virtualEntries.set(specifier, { source, options });\n return this;\n }\n\n virtualFile(specifier: string, filePath: string, options?: Partial<ModuleSource>): ModuleResolver {\n this.virtualFiles.set(specifier, { filePath, options });\n return this;\n }\n\n sourceTree(prefix: string, loader: ModuleResolverSourceLoader): ModuleResolver {\n this.sourceTrees.push({ prefix, loader });\n return this;\n }\n\n fallback(loader: ModuleResolverFallback): ModuleResolver {\n this.fallbackLoader = loader;\n return this;\n }\n\n async resolve(specifier: string, importer: { path: string; resolveDir: string }, context: HostCallContext): Promise<ModuleSource> {\n const explicit = this.virtualEntries.get(specifier);\n if (explicit) {\n const raw = typeof explicit.source === \"function\" ? await explicit.source() : await explicit.source;\n const normalized = await normalizeExplicitModuleResult(specifier, raw, importer.resolveDir);\n if (!normalized) {\n throw new Error(`Virtual module ${specifier} returned no source.`);\n }\n return {\n ...normalized,\n ...explicit.options,\n };\n }\n\n const virtualFile = this.virtualFiles.get(specifier);\n if (virtualFile) {\n const code = fs.readFileSync(virtualFile.filePath, \"utf-8\");\n const fallback = await normalizeExplicitModuleResult(\n specifier,\n {\n code,\n filename: virtualFile.options?.filename ?? path.basename(virtualFile.filePath),\n resolveDir: virtualFile.options?.resolveDir ?? path.posix.dirname(specifier.startsWith(\"/\") ? specifier : `/${specifier}`),\n static: virtualFile.options?.static,\n },\n importer.resolveDir,\n );\n if (!fallback) {\n throw new Error(`Virtual file module ${specifier} returned no source.`);\n }\n return fallback;\n }\n\n for (const sourceTree of this.sourceTrees) {\n if (!specifier.startsWith(sourceTree.prefix)) {\n continue;\n }\n const relativePath = specifier.slice(sourceTree.prefix.length);\n const normalized = await normalizeExplicitModuleResult(specifier, sourceTree.loader(relativePath, context), importer.resolveDir);\n if (normalized) {\n return normalized;\n }\n }\n\n if (this.nodeModuleMappings.length > 0) {\n try {\n return await this.getNodeModulesLoader()(specifier, importer);\n } catch (error) {\n if (!this.fallbackLoader) {\n throw error;\n }\n }\n }\n\n if (this.fallbackLoader) {\n const normalized = await normalizeExplicitModuleResult(specifier, this.fallbackLoader(specifier, importer, context), importer.resolveDir);\n if (normalized) {\n return normalized;\n }\n }\n\n throw new Error(`Unable to resolve module: ${specifier}`);\n }\n\n private getNodeModulesLoader(): ReturnType<typeof defaultModuleLoader> {\n if (!this.nodeModulesLoader) {\n this.nodeModulesLoader = defaultModuleLoader(...this.nodeModuleMappings);\n }\n return this.nodeModulesLoader;\n }\n}\n\nexport function createModuleResolver(): ModuleResolver {\n return new ModuleResolverBuilder();\n}\n"
|
|
6
6
|
],
|
|
7
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAe,IAAf;AACiB,IAAjB;AACoC,IAApC;AAC8C,IAA9C;AAAA;AAGA,MAAM,sBAAgD;AAAA,EACnC,qBAA0D,CAAC;AAAA,EAC3D,iBAAiB,IAAI;AAAA,EACrB,eAAe,IAAI;AAAA,EACnB,cAA6E,CAAC;AAAA,EACvF;AAAA,EAER,gBAAgB,CAAC,cAAsB,UAAkC;AAAA,IACvE,KAAK,mBAAmB,KAAK,EAAE,MAAM,UAAU,IAAI,aAAa,CAAC;AAAA,IACjE,OAAO;AAAA;AAAA,EAGT,OAAO,CAAC,WAAmB,QAA2D,SAAiD;AAAA,IACrI,KAAK,eAAe,IAAI,WAAW,EAAE,QAAQ,QAAQ,CAAC;AAAA,IACtD,OAAO;AAAA;AAAA,EAGT,WAAW,CAAC,WAAmB,UAAkB,SAAiD;AAAA,IAChG,KAAK,aAAa,IAAI,WAAW,EAAE,UAAU,QAAQ,CAAC;AAAA,IACtD,OAAO;AAAA;AAAA,EAGT,UAAU,CAAC,QAAgB,QAAoD;AAAA,IAC7E,KAAK,YAAY,KAAK,EAAE,QAAQ,OAAO,CAAC;AAAA,IACxC,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AAM,KAAK,qBAAqB,EAAE,WAAW,QAAQ;AAAA,QAC5D,OAAO,OAAO;AAAA,QACd,IAAI,CAAC,KAAK,gBAAgB;AAAA,UACxB,MAAM;AAAA,QACR;AAAA;AAAA,IAEJ;AAAA,IAEA,IAAI,KAAK,gBAAgB;AAAA,MACvB,MAAM,aAAa,MAAM,qDAA8B,WAAW,KAAK,eAAe,WAAW,UAAU,OAAO,GAAG,SAAS,UAAU;AAAA,MACxI,IAAI,YAAY;AAAA,QACd,OAAO;AAAA,MACT;AAAA,IACF;AAAA,IAEA,MAAM,IAAI,MAAM,6BAA6B,WAAW;AAAA;AAAA,EAGlD,oBAAoB,GAA2C;AAAA,IACrE,IAAI,CAAC,KAAK,mBAAmB;AAAA,MAC3B,KAAK,oBAAoB,yCAAoB,GAAG,KAAK,kBAAkB;AAAA,IACzE;AAAA,IACA,OAAO,KAAK;AAAA;AAEhB;AAEO,SAAS,oBAAoB,GAAmB;AAAA,EACrD,OAAO,IAAI;AAAA;",
|
|
8
|
+
"debugId": "363B95C4D202910564756E2164756E21",
|
|
9
9
|
"names": []
|
|
10
10
|
}
|
package/dist/cjs/package.json
CHANGED
|
@@ -10,8 +10,10 @@ class ModuleResolverBuilder {
|
|
|
10
10
|
virtualFiles = new Map;
|
|
11
11
|
sourceTrees = [];
|
|
12
12
|
fallbackLoader;
|
|
13
|
+
nodeModulesLoader;
|
|
13
14
|
mountNodeModules(virtualMount, hostPath) {
|
|
14
15
|
this.nodeModuleMappings.push({ from: hostPath, to: virtualMount });
|
|
16
|
+
this.nodeModulesLoader = undefined;
|
|
15
17
|
return this;
|
|
16
18
|
}
|
|
17
19
|
virtual(specifier, source, options) {
|
|
@@ -68,9 +70,8 @@ class ModuleResolverBuilder {
|
|
|
68
70
|
}
|
|
69
71
|
}
|
|
70
72
|
if (this.nodeModuleMappings.length > 0) {
|
|
71
|
-
const mappedLoader = defaultModuleLoader(...this.nodeModuleMappings);
|
|
72
73
|
try {
|
|
73
|
-
return await
|
|
74
|
+
return await this.getNodeModulesLoader()(specifier, importer);
|
|
74
75
|
} catch (error) {
|
|
75
76
|
if (!this.fallbackLoader) {
|
|
76
77
|
throw error;
|
|
@@ -85,6 +86,12 @@ class ModuleResolverBuilder {
|
|
|
85
86
|
}
|
|
86
87
|
throw new Error(`Unable to resolve module: ${specifier}`);
|
|
87
88
|
}
|
|
89
|
+
getNodeModulesLoader() {
|
|
90
|
+
if (!this.nodeModulesLoader) {
|
|
91
|
+
this.nodeModulesLoader = defaultModuleLoader(...this.nodeModuleMappings);
|
|
92
|
+
}
|
|
93
|
+
return this.nodeModulesLoader;
|
|
94
|
+
}
|
|
88
95
|
}
|
|
89
96
|
function createModuleResolver() {
|
|
90
97
|
return new ModuleResolverBuilder;
|
|
@@ -93,4 +100,4 @@ export {
|
|
|
93
100
|
createModuleResolver
|
|
94
101
|
};
|
|
95
102
|
|
|
96
|
-
//# debugId=
|
|
103
|
+
//# debugId=4DA1BAD5AFE3BC2B64756E2164756E21
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/modules/index.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"import fs from \"node:fs\";\nimport path from \"node:path\";\nimport { defaultModuleLoader } from \"../internal/module-loader/index.mjs\";\nimport { normalizeExplicitModuleResult } from \"../bridge/legacy-adapters.mjs\";\nimport type { HostCallContext, ModuleResolveResult, ModuleResolver, ModuleResolverFallback, ModuleResolverSourceLoader, ModuleSource } from \"../types.mjs\";\n\nclass ModuleResolverBuilder implements ModuleResolver {\n private readonly nodeModuleMappings: Array<{ from: string; to: string }> = [];\n private readonly virtualEntries = new Map<string, { source: ModuleResolveResult | (() => ModuleResolveResult); options?: Partial<ModuleSource> }>();\n private readonly virtualFiles = new Map<string, { filePath: string; options?: Partial<ModuleSource> }>();\n private readonly sourceTrees: Array<{ prefix: string; loader: ModuleResolverSourceLoader }> = [];\n private fallbackLoader?: ModuleResolverFallback;\n\n mountNodeModules(virtualMount: string, hostPath: string): ModuleResolver {\n this.nodeModuleMappings.push({ from: hostPath, to: virtualMount });\n return this;\n }\n\n virtual(specifier: string, source: ModuleResolveResult | (() => ModuleResolveResult), options?: Partial<ModuleSource>): ModuleResolver {\n this.virtualEntries.set(specifier, { source, options });\n return this;\n }\n\n virtualFile(specifier: string, filePath: string, options?: Partial<ModuleSource>): ModuleResolver {\n this.virtualFiles.set(specifier, { filePath, options });\n return this;\n }\n\n sourceTree(prefix: string, loader: ModuleResolverSourceLoader): ModuleResolver {\n this.sourceTrees.push({ prefix, loader });\n return this;\n }\n\n fallback(loader: ModuleResolverFallback): ModuleResolver {\n this.fallbackLoader = loader;\n return this;\n }\n\n async resolve(specifier: string, importer: { path: string; resolveDir: string }, context: HostCallContext): Promise<ModuleSource> {\n const explicit = this.virtualEntries.get(specifier);\n if (explicit) {\n const raw = typeof explicit.source === \"function\" ? await explicit.source() : await explicit.source;\n const normalized = await normalizeExplicitModuleResult(specifier, raw, importer.resolveDir);\n if (!normalized) {\n throw new Error(`Virtual module ${specifier} returned no source.`);\n }\n return {\n ...normalized,\n ...explicit.options,\n };\n }\n\n const virtualFile = this.virtualFiles.get(specifier);\n if (virtualFile) {\n const code = fs.readFileSync(virtualFile.filePath, \"utf-8\");\n const fallback = await normalizeExplicitModuleResult(\n specifier,\n {\n code,\n filename: virtualFile.options?.filename ?? path.basename(virtualFile.filePath),\n resolveDir: virtualFile.options?.resolveDir ?? path.posix.dirname(specifier.startsWith(\"/\") ? specifier : `/${specifier}`),\n static: virtualFile.options?.static,\n },\n importer.resolveDir,\n );\n if (!fallback) {\n throw new Error(`Virtual file module ${specifier} returned no source.`);\n }\n return fallback;\n }\n\n for (const sourceTree of this.sourceTrees) {\n if (!specifier.startsWith(sourceTree.prefix)) {\n continue;\n }\n const relativePath = specifier.slice(sourceTree.prefix.length);\n const normalized = await normalizeExplicitModuleResult(specifier, sourceTree.loader(relativePath, context), importer.resolveDir);\n if (normalized) {\n return normalized;\n }\n }\n\n if (this.nodeModuleMappings.length > 0) {\n
|
|
5
|
+
"import fs from \"node:fs\";\nimport path from \"node:path\";\nimport { defaultModuleLoader } from \"../internal/module-loader/index.mjs\";\nimport { normalizeExplicitModuleResult } from \"../bridge/legacy-adapters.mjs\";\nimport type { HostCallContext, ModuleResolveResult, ModuleResolver, ModuleResolverFallback, ModuleResolverSourceLoader, ModuleSource } from \"../types.mjs\";\n\nclass ModuleResolverBuilder implements ModuleResolver {\n private readonly nodeModuleMappings: Array<{ from: string; to: string }> = [];\n private readonly virtualEntries = new Map<string, { source: ModuleResolveResult | (() => ModuleResolveResult); options?: Partial<ModuleSource> }>();\n private readonly virtualFiles = new Map<string, { filePath: string; options?: Partial<ModuleSource> }>();\n private readonly sourceTrees: Array<{ prefix: string; loader: ModuleResolverSourceLoader }> = [];\n private fallbackLoader?: ModuleResolverFallback;\n private nodeModulesLoader?: ReturnType<typeof defaultModuleLoader>;\n\n mountNodeModules(virtualMount: string, hostPath: string): ModuleResolver {\n this.nodeModuleMappings.push({ from: hostPath, to: virtualMount });\n this.nodeModulesLoader = undefined;\n return this;\n }\n\n virtual(specifier: string, source: ModuleResolveResult | (() => ModuleResolveResult), options?: Partial<ModuleSource>): ModuleResolver {\n this.virtualEntries.set(specifier, { source, options });\n return this;\n }\n\n virtualFile(specifier: string, filePath: string, options?: Partial<ModuleSource>): ModuleResolver {\n this.virtualFiles.set(specifier, { filePath, options });\n return this;\n }\n\n sourceTree(prefix: string, loader: ModuleResolverSourceLoader): ModuleResolver {\n this.sourceTrees.push({ prefix, loader });\n return this;\n }\n\n fallback(loader: ModuleResolverFallback): ModuleResolver {\n this.fallbackLoader = loader;\n return this;\n }\n\n async resolve(specifier: string, importer: { path: string; resolveDir: string }, context: HostCallContext): Promise<ModuleSource> {\n const explicit = this.virtualEntries.get(specifier);\n if (explicit) {\n const raw = typeof explicit.source === \"function\" ? await explicit.source() : await explicit.source;\n const normalized = await normalizeExplicitModuleResult(specifier, raw, importer.resolveDir);\n if (!normalized) {\n throw new Error(`Virtual module ${specifier} returned no source.`);\n }\n return {\n ...normalized,\n ...explicit.options,\n };\n }\n\n const virtualFile = this.virtualFiles.get(specifier);\n if (virtualFile) {\n const code = fs.readFileSync(virtualFile.filePath, \"utf-8\");\n const fallback = await normalizeExplicitModuleResult(\n specifier,\n {\n code,\n filename: virtualFile.options?.filename ?? path.basename(virtualFile.filePath),\n resolveDir: virtualFile.options?.resolveDir ?? path.posix.dirname(specifier.startsWith(\"/\") ? specifier : `/${specifier}`),\n static: virtualFile.options?.static,\n },\n importer.resolveDir,\n );\n if (!fallback) {\n throw new Error(`Virtual file module ${specifier} returned no source.`);\n }\n return fallback;\n }\n\n for (const sourceTree of this.sourceTrees) {\n if (!specifier.startsWith(sourceTree.prefix)) {\n continue;\n }\n const relativePath = specifier.slice(sourceTree.prefix.length);\n const normalized = await normalizeExplicitModuleResult(specifier, sourceTree.loader(relativePath, context), importer.resolveDir);\n if (normalized) {\n return normalized;\n }\n }\n\n if (this.nodeModuleMappings.length > 0) {\n try {\n return await this.getNodeModulesLoader()(specifier, importer);\n } catch (error) {\n if (!this.fallbackLoader) {\n throw error;\n }\n }\n }\n\n if (this.fallbackLoader) {\n const normalized = await normalizeExplicitModuleResult(specifier, this.fallbackLoader(specifier, importer, context), importer.resolveDir);\n if (normalized) {\n return normalized;\n }\n }\n\n throw new Error(`Unable to resolve module: ${specifier}`);\n }\n\n private getNodeModulesLoader(): ReturnType<typeof defaultModuleLoader> {\n if (!this.nodeModulesLoader) {\n this.nodeModulesLoader = defaultModuleLoader(...this.nodeModuleMappings);\n }\n return this.nodeModulesLoader;\n }\n}\n\nexport function createModuleResolver(): ModuleResolver {\n return new ModuleResolverBuilder();\n}\n"
|
|
6
6
|
],
|
|
7
|
-
"mappings": ";AAAA;AACA;AACA;AACA;AAAA;AAGA,MAAM,sBAAgD;AAAA,EACnC,qBAA0D,CAAC;AAAA,EAC3D,iBAAiB,IAAI;AAAA,EACrB,eAAe,IAAI;A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
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Unified runtime host for app servers, script runtimes, browser runtimes, module resolution, file bindings, and typechecking",
|
|
6
6
|
"author": "ricsam <oss@ricsam.dev>",
|