@dxos/functions 0.8.4-main.5acf9ea → 0.8.4-main.5ea62a8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/browser/bundler/index.mjs +54 -38
- package/dist/lib/browser/bundler/index.mjs.map +3 -3
- package/dist/lib/browser/chunk-7NQ77AIQ.mjs +618 -0
- package/dist/lib/browser/chunk-7NQ77AIQ.mjs.map +7 -0
- package/dist/lib/browser/edge/index.mjs +20 -8
- package/dist/lib/browser/edge/index.mjs.map +3 -3
- package/dist/lib/browser/index.mjs +141 -77
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +68 -5
- package/dist/lib/browser/testing/index.mjs.map +3 -3
- package/dist/lib/node-esm/bundler/index.mjs +54 -38
- package/dist/lib/node-esm/bundler/index.mjs.map +3 -3
- package/dist/lib/node-esm/chunk-KCGC6QQT.mjs +620 -0
- package/dist/lib/node-esm/chunk-KCGC6QQT.mjs.map +7 -0
- package/dist/lib/node-esm/edge/index.mjs +20 -8
- package/dist/lib/node-esm/edge/index.mjs.map +3 -3
- package/dist/lib/node-esm/index.mjs +141 -77
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/testing/index.mjs +68 -5
- package/dist/lib/node-esm/testing/index.mjs.map +3 -3
- package/dist/types/src/bundler/bundler.d.ts +11 -12
- package/dist/types/src/bundler/bundler.d.ts.map +1 -1
- package/dist/types/src/edge/functions.d.ts +3 -2
- package/dist/types/src/edge/functions.d.ts.map +1 -1
- package/dist/types/src/errors.d.ts +10 -8
- package/dist/types/src/errors.d.ts.map +1 -1
- package/dist/types/src/examples/fib.d.ts +7 -0
- package/dist/types/src/examples/fib.d.ts.map +1 -0
- package/dist/types/src/examples/reply.d.ts +3 -0
- package/dist/types/src/examples/reply.d.ts.map +1 -0
- package/dist/types/src/examples/sleep.d.ts +5 -0
- package/dist/types/src/examples/sleep.d.ts.map +1 -0
- package/dist/types/src/executor/executor.d.ts +4 -1
- package/dist/types/src/executor/executor.d.ts.map +1 -1
- package/dist/types/src/handler.d.ts +10 -7
- package/dist/types/src/handler.d.ts.map +1 -1
- package/dist/types/src/schema.d.ts +7 -2
- package/dist/types/src/schema.d.ts.map +1 -1
- package/dist/types/src/services/credentials.d.ts +15 -3
- package/dist/types/src/services/credentials.d.ts.map +1 -1
- package/dist/types/src/services/database.d.ts +74 -6
- package/dist/types/src/services/database.d.ts.map +1 -1
- package/dist/types/src/services/event-logger.d.ts +1 -1
- package/dist/types/src/services/event-logger.d.ts.map +1 -1
- package/dist/types/src/services/local-function-execution.d.ts +2 -1
- package/dist/types/src/services/local-function-execution.d.ts.map +1 -1
- package/dist/types/src/services/queues.d.ts +18 -5
- package/dist/types/src/services/queues.d.ts.map +1 -1
- package/dist/types/src/services/remote-function-execution-service.d.ts.map +1 -1
- package/dist/types/src/services/service-container.d.ts +1 -1
- package/dist/types/src/services/service-container.d.ts.map +1 -1
- package/dist/types/src/services/service-registry.d.ts.map +1 -1
- package/dist/types/src/services/tracing.d.ts +33 -3
- package/dist/types/src/services/tracing.d.ts.map +1 -1
- package/dist/types/src/testing/layer.d.ts +6 -2
- package/dist/types/src/testing/layer.d.ts.map +1 -1
- package/dist/types/src/testing/logger.d.ts.map +1 -1
- package/dist/types/src/testing/persist-database.test.d.ts +2 -0
- package/dist/types/src/testing/persist-database.test.d.ts.map +1 -0
- package/dist/types/src/testing/services.d.ts +1 -1
- package/dist/types/src/testing/services.d.ts.map +1 -1
- package/dist/types/src/trace.d.ts +34 -8
- package/dist/types/src/trace.d.ts.map +1 -1
- package/dist/types/src/types.d.ts +141 -224
- package/dist/types/src/types.d.ts.map +1 -1
- package/dist/types/src/url.d.ts +10 -6
- package/dist/types/src/url.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +40 -39
- package/src/bundler/bundler.test.ts +8 -9
- package/src/bundler/bundler.ts +32 -33
- package/src/edge/functions.ts +8 -5
- package/src/examples/fib.ts +30 -0
- package/src/examples/reply.ts +18 -0
- package/src/examples/sleep.ts +22 -0
- package/src/executor/executor.ts +9 -9
- package/src/handler.ts +12 -10
- package/src/schema.ts +11 -0
- package/src/services/credentials.ts +78 -5
- package/src/services/database.ts +114 -18
- package/src/services/event-logger.ts +2 -2
- package/src/services/local-function-execution.ts +20 -13
- package/src/services/queues.ts +29 -10
- package/src/services/remote-function-execution-service.ts +2 -22
- package/src/services/service-container.ts +4 -3
- package/src/services/service-registry.ts +1 -1
- package/src/services/tracing.ts +95 -5
- package/src/testing/layer.ts +69 -3
- package/src/testing/logger.ts +1 -1
- package/src/testing/persist-database.test.ts +87 -0
- package/src/testing/services.ts +2 -1
- package/src/trace.ts +5 -7
- package/src/types.ts +17 -25
- package/src/url.ts +13 -10
- package/dist/lib/browser/chunk-6PTFLPCO.mjs +0 -462
- package/dist/lib/browser/chunk-6PTFLPCO.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-NYJ2TSXO.mjs +0 -464
- package/dist/lib/node-esm/chunk-NYJ2TSXO.mjs.map +0 -7
|
@@ -2,36 +2,40 @@ import { createRequire } from 'node:module';const require = createRequire(import
|
|
|
2
2
|
|
|
3
3
|
// src/bundler/bundler.ts
|
|
4
4
|
import { FetchHttpClient, HttpClient } from "@effect/platform";
|
|
5
|
-
import { Duration, Effect,
|
|
5
|
+
import { Duration, Effect, Schedule, pipe } from "effect";
|
|
6
6
|
import { build, initialize } from "esbuild-wasm";
|
|
7
7
|
import { subtleCrypto } from "@dxos/crypto";
|
|
8
8
|
import { runAndForwardErrors } from "@dxos/effect";
|
|
9
9
|
import { invariant } from "@dxos/invariant";
|
|
10
10
|
import { log } from "@dxos/log";
|
|
11
|
+
function _define_property(obj, key, value) {
|
|
12
|
+
if (key in obj) {
|
|
13
|
+
Object.defineProperty(obj, key, {
|
|
14
|
+
value,
|
|
15
|
+
enumerable: true,
|
|
16
|
+
configurable: true,
|
|
17
|
+
writable: true
|
|
18
|
+
});
|
|
19
|
+
} else {
|
|
20
|
+
obj[key] = value;
|
|
21
|
+
}
|
|
22
|
+
return obj;
|
|
23
|
+
}
|
|
11
24
|
var __dxlog_file = "/__w/dxos/dxos/packages/core/functions/src/bundler/bundler.ts";
|
|
12
25
|
var initialized;
|
|
13
26
|
var initializeBundler = async (options) => {
|
|
14
|
-
await (initialized
|
|
27
|
+
await (initialized ?? (initialized = initialize({
|
|
15
28
|
wasmURL: options.wasmUrl
|
|
16
|
-
}));
|
|
29
|
+
})));
|
|
17
30
|
};
|
|
18
31
|
var Bundler = class {
|
|
19
|
-
|
|
20
|
-
this._options = _options;
|
|
21
|
-
}
|
|
22
|
-
async bundle({ path, source }) {
|
|
32
|
+
async bundle({ source }) {
|
|
23
33
|
const { sandboxedModules: providedModules, ...options } = this._options;
|
|
24
|
-
const
|
|
25
|
-
return {
|
|
26
|
-
timestamp: Date.now(),
|
|
27
|
-
sourceHash: source ? Buffer.from(await subtleCrypto.digest("SHA-256", Buffer.from(source))) : void 0,
|
|
28
|
-
...result
|
|
29
|
-
};
|
|
30
|
-
};
|
|
34
|
+
const sourceHash = Buffer.from(await subtleCrypto.digest("SHA-256", Buffer.from(source)));
|
|
31
35
|
if (this._options.platform === "browser") {
|
|
32
36
|
invariant(initialized, "Compiler not initialized.", {
|
|
33
37
|
F: __dxlog_file,
|
|
34
|
-
L:
|
|
38
|
+
L: 66,
|
|
35
39
|
S: this,
|
|
36
40
|
A: [
|
|
37
41
|
"initialized",
|
|
@@ -50,9 +54,10 @@ var Bundler = class {
|
|
|
50
54
|
],
|
|
51
55
|
metafile: true,
|
|
52
56
|
write: false,
|
|
53
|
-
entryPoints:
|
|
54
|
-
|
|
55
|
-
|
|
57
|
+
entryPoints: {
|
|
58
|
+
// Gets mapped to `userFunc.js` by esbuild.
|
|
59
|
+
userFunc: "memory:main.tsx"
|
|
60
|
+
},
|
|
56
61
|
bundle: true,
|
|
57
62
|
format: "esm",
|
|
58
63
|
plugins: [
|
|
@@ -61,15 +66,15 @@ var Bundler = class {
|
|
|
61
66
|
setup: (build2) => {
|
|
62
67
|
build2.onResolve({
|
|
63
68
|
filter: /^\.\/runtime\.js$/
|
|
64
|
-
}, ({ path
|
|
69
|
+
}, ({ path }) => {
|
|
65
70
|
return {
|
|
66
|
-
path
|
|
71
|
+
path,
|
|
67
72
|
external: true
|
|
68
73
|
};
|
|
69
74
|
});
|
|
70
75
|
build2.onResolve({
|
|
71
76
|
filter: /^dxos:functions$/
|
|
72
|
-
}, ({ path
|
|
77
|
+
}, ({ path }) => {
|
|
73
78
|
return {
|
|
74
79
|
path: "./runtime.js",
|
|
75
80
|
external: true
|
|
@@ -77,17 +82,17 @@ var Bundler = class {
|
|
|
77
82
|
});
|
|
78
83
|
build2.onResolve({
|
|
79
84
|
filter: /^memory:/
|
|
80
|
-
}, ({ path
|
|
85
|
+
}, ({ path }) => {
|
|
81
86
|
return {
|
|
82
|
-
path:
|
|
87
|
+
path: path.split(":")[1],
|
|
83
88
|
namespace: "memory"
|
|
84
89
|
};
|
|
85
90
|
});
|
|
86
91
|
build2.onLoad({
|
|
87
92
|
filter: /.*/,
|
|
88
93
|
namespace: "memory"
|
|
89
|
-
}, ({ path
|
|
90
|
-
if (
|
|
94
|
+
}, ({ path }) => {
|
|
95
|
+
if (path === "main.tsx") {
|
|
91
96
|
return {
|
|
92
97
|
contents: source,
|
|
93
98
|
loader: "tsx"
|
|
@@ -97,9 +102,9 @@ var Bundler = class {
|
|
|
97
102
|
for (const module of providedModules) {
|
|
98
103
|
build2.onResolve({
|
|
99
104
|
filter: new RegExp(`^${module}$`)
|
|
100
|
-
}, ({ path
|
|
105
|
+
}, ({ path }) => {
|
|
101
106
|
return {
|
|
102
|
-
path
|
|
107
|
+
path,
|
|
103
108
|
namespace: "injected-module"
|
|
104
109
|
};
|
|
105
110
|
});
|
|
@@ -107,13 +112,13 @@ var Bundler = class {
|
|
|
107
112
|
build2.onLoad({
|
|
108
113
|
filter: /.*/,
|
|
109
114
|
namespace: "injected-module"
|
|
110
|
-
}, ({ path
|
|
111
|
-
const namedImports = imports.find((entry) => entry.moduleIdentifier ===
|
|
115
|
+
}, ({ path }) => {
|
|
116
|
+
const namedImports = imports.find((entry) => entry.moduleIdentifier === path)?.namedImports ?? [];
|
|
112
117
|
return {
|
|
113
118
|
contents: `
|
|
114
|
-
const { ${namedImports.join(",")} } = window.__DXOS_SANDBOX_MODULES__[${JSON.stringify(
|
|
119
|
+
const { ${namedImports.join(",")} } = window.__DXOS_SANDBOX_MODULES__[${JSON.stringify(path)}];
|
|
115
120
|
export { ${namedImports.join(",")} };
|
|
116
|
-
export default window.__DXOS_SANDBOX_MODULES__[${JSON.stringify(
|
|
121
|
+
export default window.__DXOS_SANDBOX_MODULES__[${JSON.stringify(path)}].default;
|
|
117
122
|
`,
|
|
118
123
|
loader: "tsx"
|
|
119
124
|
};
|
|
@@ -125,25 +130,32 @@ var Bundler = class {
|
|
|
125
130
|
});
|
|
126
131
|
log("compile complete", result.metafile, {
|
|
127
132
|
F: __dxlog_file,
|
|
128
|
-
L:
|
|
133
|
+
L: 133,
|
|
129
134
|
S: this,
|
|
130
135
|
C: (f, a) => f(...a)
|
|
131
136
|
});
|
|
132
|
-
|
|
137
|
+
const entryPoint = "userFunc.js";
|
|
138
|
+
return {
|
|
139
|
+
timestamp: Date.now(),
|
|
140
|
+
sourceHash,
|
|
133
141
|
imports: this.analyzeImports(result),
|
|
142
|
+
entryPoint,
|
|
143
|
+
asset: result.outputFiles[0].contents,
|
|
134
144
|
bundle: result.outputFiles[0].text
|
|
135
|
-
}
|
|
145
|
+
};
|
|
136
146
|
} catch (err) {
|
|
137
|
-
return
|
|
147
|
+
return {
|
|
148
|
+
timestamp: Date.now(),
|
|
149
|
+
sourceHash,
|
|
138
150
|
error: err
|
|
139
|
-
}
|
|
151
|
+
};
|
|
140
152
|
}
|
|
141
153
|
}
|
|
142
154
|
// TODO(dmaretskyi): In the future we can replace the compiler with SWC with plugins running in WASM.
|
|
143
155
|
analyzeImports(result) {
|
|
144
156
|
invariant(result.outputFiles, void 0, {
|
|
145
157
|
F: __dxlog_file,
|
|
146
|
-
L:
|
|
158
|
+
L: 151,
|
|
147
159
|
S: this,
|
|
148
160
|
A: [
|
|
149
161
|
"result.outputFiles",
|
|
@@ -182,13 +194,17 @@ var Bundler = class {
|
|
|
182
194
|
};
|
|
183
195
|
});
|
|
184
196
|
}
|
|
197
|
+
constructor(_options) {
|
|
198
|
+
_define_property(this, "_options", void 0);
|
|
199
|
+
this._options = _options;
|
|
200
|
+
}
|
|
185
201
|
};
|
|
186
202
|
var IMPORT_REGEX = /import(?:(?:(?:[ \n\t]+([^ *\n\t{},]+)[ \n\t]*(?:,|[ \n\t]+))?([ \n\t]*{(?:[ \n\t]*[^ \n\t"'{}]+[ \n\t]*,?)+})?[ \n\t]*)|[ \n\t]*\*[ \n\t]*as[ \n\t]+([^ \n\t{}]+)[ \n\t]+)from[ \n\t]*(?:['"])([^'"\n]+)(['"])/gm;
|
|
187
203
|
var NAMED_IMPORTS_REGEX = /[ \n\t]*{((?:[ \n\t]*[^ \n\t"'{}]+[ \n\t]*,?)+)}[ \n\t]*/gm;
|
|
188
204
|
var allMatches = (regex, str) => {
|
|
189
|
-
regex.lastIndex = 0;
|
|
190
205
|
let match;
|
|
191
206
|
const matches = [];
|
|
207
|
+
regex.lastIndex = 0;
|
|
192
208
|
while (match = regex.exec(str)) {
|
|
193
209
|
matches.push(match);
|
|
194
210
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/bundler/bundler.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { FetchHttpClient, HttpClient } from '@effect/platform';\nimport { Duration, Effect,
|
|
5
|
-
"mappings": ";;;AAIA,SAASA,iBAAiBC,kBAAkB;AAC5C,SAASC,UAAUC,QAAQC,
|
|
6
|
-
"names": ["FetchHttpClient", "HttpClient", "Duration", "Effect", "
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { FetchHttpClient, HttpClient } from '@effect/platform';\nimport { Duration, Effect, Schedule, pipe } from 'effect';\nimport { type BuildOptions, type BuildResult, type Loader, type Plugin, build, initialize } from 'esbuild-wasm';\n\nimport { subtleCrypto } from '@dxos/crypto';\nimport { runAndForwardErrors } from '@dxos/effect';\nimport { invariant } from '@dxos/invariant';\nimport { log } from '@dxos/log';\n\nexport type Import = {\n moduleUrl: string;\n defaultImport: boolean;\n namedImports: string[];\n};\n\nexport type BundleOptions = {\n /**\n * Source code to bundle.\n */\n source: string;\n};\n\nexport type BundleResult =\n | {\n timestamp: number;\n sourceHash: Buffer;\n error: unknown;\n }\n | {\n timestamp: number;\n sourceHash: Buffer;\n imports: Import[];\n entryPoint: string;\n asset: Uint8Array;\n bundle: string;\n };\n\nexport type BundlerOptions = {\n platform: BuildOptions['platform'];\n sandboxedModules: string[];\n remoteModules: Record<string, string>;\n};\n\nlet initialized: Promise<void>;\nexport const initializeBundler = async (options: { wasmUrl: string }) => {\n await (initialized ??= initialize({\n wasmURL: options.wasmUrl,\n }));\n};\n\n/**\n * ESBuild bundler.\n */\nexport class Bundler {\n constructor(private readonly _options: BundlerOptions) {}\n\n async bundle({ source }: BundleOptions): Promise<BundleResult> {\n const { sandboxedModules: providedModules, ...options } = this._options;\n const sourceHash = Buffer.from(await subtleCrypto.digest('SHA-256', Buffer.from(source)));\n\n if (this._options.platform === 'browser') {\n invariant(initialized, 'Compiler not initialized.');\n await initialized;\n }\n\n const imports = source ? analyzeSourceFileImports(source) : [];\n\n // https://esbuild.github.io/api/#build\n try {\n const result = await build({\n platform: options.platform,\n conditions: ['workerd', 'browser'],\n metafile: true,\n write: false,\n entryPoints: {\n // Gets mapped to `userFunc.js` by esbuild.\n userFunc: 'memory:main.tsx',\n },\n bundle: true,\n format: 'esm',\n plugins: [\n {\n name: 'memory',\n setup: (build) => {\n build.onResolve({ filter: /^\\.\\/runtime\\.js$/ }, ({ path }) => {\n return { path, external: true };\n });\n\n build.onResolve({ filter: /^dxos:functions$/ }, ({ path }) => {\n return { path: './runtime.js', external: true };\n });\n\n build.onResolve({ filter: /^memory:/ }, ({ path }) => {\n return { path: path.split(':')[1], namespace: 'memory' };\n });\n\n build.onLoad({ filter: /.*/, namespace: 'memory' }, ({ path }) => {\n if (path === 'main.tsx') {\n return {\n contents: source,\n loader: 'tsx',\n };\n }\n });\n\n for (const module of providedModules) {\n build.onResolve({ filter: new RegExp(`^${module}$`) }, ({ path }) => {\n return { path, namespace: 'injected-module' };\n });\n }\n\n build.onLoad({ filter: /.*/, namespace: 'injected-module' }, ({ path }) => {\n const namedImports = imports.find((entry) => entry.moduleIdentifier === path)?.namedImports ?? [];\n return {\n contents: `\n const { ${namedImports.join(',')} } = window.__DXOS_SANDBOX_MODULES__[${JSON.stringify(path)}];\n export { ${namedImports.join(',')} };\n export default window.__DXOS_SANDBOX_MODULES__[${JSON.stringify(path)}].default;\n `,\n loader: 'tsx',\n };\n });\n },\n },\n httpPlugin,\n ],\n });\n\n log('compile complete', result.metafile);\n\n const entryPoint = 'userFunc.js';\n return {\n timestamp: Date.now(),\n sourceHash,\n imports: this.analyzeImports(result),\n entryPoint,\n asset: result.outputFiles![0].contents,\n bundle: result.outputFiles![0].text,\n };\n } catch (err) {\n return { timestamp: Date.now(), sourceHash, error: err };\n }\n }\n\n // TODO(dmaretskyi): In the future we can replace the compiler with SWC with plugins running in WASM.\n analyzeImports(result: BuildResult): Import[] {\n invariant(result.outputFiles);\n\n // TODO(dmaretskyi): Support import aliases and wildcard imports.\n const parsedImports = allMatches(IMPORT_REGEX, result.outputFiles[0].text);\n return Object.values(result.metafile!.outputs)[0].imports.map((entry): Import => {\n const namedImports: string[] = [];\n const parsedImport = parsedImports.find((capture) => capture?.[4] === entry.path);\n if (parsedImport?.[2]) {\n NAMED_IMPORTS_REGEX.lastIndex = 0;\n const namedImportsMatch = NAMED_IMPORTS_REGEX.exec(parsedImport[2]);\n if (namedImportsMatch) {\n namedImportsMatch[1].split(',').forEach((importName) => {\n namedImports.push(importName.trim());\n });\n }\n }\n\n return {\n moduleUrl: entry.path,\n defaultImport: !!parsedImport?.[1],\n namedImports,\n };\n });\n }\n\n analyzeSourceFileImports(code: string): {\n defaultImportName: string;\n namedImports: string[];\n wildcardImportName: string;\n moduleIdentifier: string;\n quotes: string;\n }[] {\n // TODO(dmaretskyi): Support import aliases and wildcard imports.\n const parsedImports = allMatches(IMPORT_REGEX, code);\n return parsedImports.map((capture) => {\n return {\n defaultImportName: capture[1],\n namedImports: capture[2]?.split(',').map((importName) => importName.trim()),\n wildcardImportName: capture[3],\n moduleIdentifier: capture[4],\n quotes: capture[5],\n };\n });\n }\n}\n\n// https://regex101.com/r/FEN5ks/1\n// https://stackoverflow.com/a/73265022\n// $1 = default import name (can be non-existent)\n// $2 = destructured exports (can be non-existent)\n// $3 = wildcard import name (can be non-existent)\n// $4 = module identifier\n// $5 = quotes used (either ' or \")\nconst IMPORT_REGEX =\n /import(?:(?:(?:[ \\n\\t]+([^ *\\n\\t{},]+)[ \\n\\t]*(?:,|[ \\n\\t]+))?([ \\n\\t]*{(?:[ \\n\\t]*[^ \\n\\t\"'{}]+[ \\n\\t]*,?)+})?[ \\n\\t]*)|[ \\n\\t]*\\*[ \\n\\t]*as[ \\n\\t]+([^ \\n\\t{}]+)[ \\n\\t]+)from[ \\n\\t]*(?:['\"])([^'\"\\n]+)(['\"])/gm;\n\nconst NAMED_IMPORTS_REGEX = /[ \\n\\t]*{((?:[ \\n\\t]*[^ \\n\\t\"'{}]+[ \\n\\t]*,?)+)}[ \\n\\t]*/gm;\n\nconst allMatches = (regex: RegExp, str: string) => {\n let match;\n const matches = [];\n regex.lastIndex = 0;\n while ((match = regex.exec(str))) {\n matches.push(match);\n }\n\n return matches;\n};\n\ntype ParsedImport = {\n defaultImportName?: string;\n namedImports: string[];\n wildcardImportName?: string;\n moduleIdentifier: string;\n quotes: string;\n};\n\nconst analyzeSourceFileImports = (code: string): ParsedImport[] => {\n // TODO(dmaretskyi): Support import aliases and wildcard imports.\n const parsedImports = allMatches(IMPORT_REGEX, code);\n return parsedImports.map((capture) => {\n return {\n defaultImportName: capture[1],\n namedImports: capture[2]\n ?.trim()\n .slice(1, -1)\n .split(',')\n .map((importName) => importName.trim()),\n wildcardImportName: capture[3],\n moduleIdentifier: capture[4],\n quotes: capture[5],\n };\n });\n};\n\nconst MAX_RETRIES = 5;\nconst INITIAL_DELAY = 1_000;\n\nconst httpPlugin: Plugin = {\n name: 'http',\n setup: (build) => {\n // Intercept import paths starting with \"http:\" and \"https:\" so esbuild doesn't attempt to map them to a file system location.\n // Tag them with the \"http-url\" namespace to associate them with this plugin.\n build.onResolve({ filter: /^https?:\\/\\// }, (args) => ({\n path: args.path,\n namespace: 'http-url',\n }));\n\n // We also want to intercept all import paths inside downloaded files and resolve them against the original URL.\n // All of these files will be in the \"http-url\" namespace.\n // Make sure to keep the newly resolved URL in the \"http-url\" namespace so imports inside it will also be resolved as URLs recursively.\n build.onResolve({ filter: /.*/, namespace: 'http-url' }, (args) => ({\n path: new URL(args.path, args.importer).toString(),\n namespace: 'http-url',\n }));\n\n // When a URL is loaded, we want to actually download the content from the internet.\n // This has just enough logic to be able to handle the example import from unpkg.com but in reality this would probably need to be more complex.\n build.onLoad({ filter: /.*/, namespace: 'http-url' }, async (args) => {\n return Effect.gen(function* () {\n const response = yield* HttpClient.get(args.path);\n if (response.status !== 200) {\n throw new Error(`failed to fetch: ${response.status}`);\n }\n\n const text = yield* response.text;\n return { contents: text, loader: 'jsx' as Loader };\n }).pipe(\n Effect.retry(\n pipe(\n Schedule.exponential(Duration.millis(INITIAL_DELAY)),\n Schedule.jittered,\n Schedule.intersect(Schedule.recurs(MAX_RETRIES - 1)),\n ),\n ),\n Effect.provide(FetchHttpClient.layer),\n runAndForwardErrors,\n );\n });\n },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AAOsD,SAAAA;AAC3D,aAAOhG,OAAOoG,IAAI,aAAA;AAChB,cAAMC,WAAW,OAAOvG,WAAWwG,IAAIN,KAAKzD,IAAI;AAChD,YAAI8D,SAASE,WAAW,KAAK;AAC3B,gBAAM,IAAIC,MAAM,oBAAoBH,SAASE,MAAM,EAAE;QACvD;AAEA,cAAMxC,OAAO,OAAOsC,SAAStC;AAC7B,eAAO;UAAEnB,UAAUmB;UAAMlB,QAAQ;QAAgB;MACnD,CAAA,EAAG3C,KACDF,OAAOyG,MACLvG,KACED,SAASyG,YAAY3G,SAAS4G,OAAOZ,aAAAA,CAAAA,GACrC9F,SAAS2G,UACT3G,SAAS4G,UAAU5G,SAAS6G,OAAOhB,cAAc,CAAA,CAAA,CAAA,CAAA,GAGrD9F,OAAO+G,QAAQlH,gBAAgBmH,KAAK,GACpC1G,mBAAAA;IAEJ,CAAA;EACF;AACF;",
|
|
6
|
+
"names": ["FetchHttpClient", "HttpClient", "Duration", "Effect", "Schedule", "pipe", "build", "initialize", "subtleCrypto", "runAndForwardErrors", "invariant", "log", "initialized", "initializeBundler", "options", "wasmURL", "wasmUrl", "Bundler", "bundle", "source", "sandboxedModules", "providedModules", "_options", "sourceHash", "Buffer", "from", "digest", "platform", "imports", "analyzeSourceFileImports", "result", "conditions", "metafile", "write", "entryPoints", "userFunc", "format", "plugins", "name", "setup", "onResolve", "filter", "path", "external", "split", "namespace", "onLoad", "contents", "loader", "module", "RegExp", "namedImports", "find", "entry", "moduleIdentifier", "join", "JSON", "stringify", "httpPlugin", "entryPoint", "timestamp", "Date", "now", "analyzeImports", "asset", "outputFiles", "text", "err", "error", "parsedImports", "allMatches", "IMPORT_REGEX", "Object", "values", "outputs", "map", "parsedImport", "capture", "NAMED_IMPORTS_REGEX", "lastIndex", "namedImportsMatch", "exec", "forEach", "importName", "push", "trim", "moduleUrl", "defaultImport", "code", "defaultImportName", "wildcardImportName", "quotes", "regex", "str", "match", "matches", "slice", "MAX_RETRIES", "INITIAL_DELAY", "args", "URL", "importer", "toString", "gen", "response", "get", "status", "Error", "retry", "exponential", "millis", "jittered", "intersect", "recurs", "provide", "layer"]
|
|
7
7
|
}
|