@dxos/functions 0.7.5-labs.ea4b4c2 → 0.7.5-labs.ff2ff30
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 +20 -20
- package/dist/lib/browser/bundler/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/bundler/index.cjs +20 -20
- package/dist/lib/node/bundler/index.cjs.map +3 -3
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node-esm/bundler/index.mjs +20 -20
- package/dist/lib/node-esm/bundler/index.mjs.map +3 -3
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/bundler/bundler.d.ts +15 -3
- package/dist/types/src/bundler/bundler.d.ts.map +1 -1
- package/package.json +18 -18
- package/src/bundler/bundler.test.ts +10 -6
- package/src/bundler/bundler.ts +21 -7
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/functions",
|
|
3
|
-
"version": "0.7.5-labs.
|
|
3
|
+
"version": "0.7.5-labs.ff2ff30",
|
|
4
4
|
"description": "Functions API and runtime.",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -66,27 +66,27 @@
|
|
|
66
66
|
"get-port-please": "^3.1.1",
|
|
67
67
|
"iso-did": "^1.6.0",
|
|
68
68
|
"ws": "^8.14.2",
|
|
69
|
-
"@dxos/async": "0.7.5-labs.
|
|
70
|
-
"@dxos/context": "0.7.5-labs.
|
|
71
|
-
"@dxos/client": "0.7.5-labs.
|
|
72
|
-
"@dxos/echo-db": "0.7.5-labs.
|
|
73
|
-
"@dxos/
|
|
74
|
-
"@dxos/echo-
|
|
75
|
-
"@dxos/
|
|
76
|
-
"@dxos/
|
|
77
|
-
"@dxos/
|
|
78
|
-
"@dxos/
|
|
79
|
-
"@dxos/
|
|
80
|
-
"@dxos/node-std": "0.7.5-labs.
|
|
81
|
-
"@dxos/
|
|
82
|
-
"@dxos/
|
|
83
|
-
"@dxos/schema": "0.7.5-labs.
|
|
84
|
-
"@dxos/util": "0.7.5-labs.
|
|
69
|
+
"@dxos/async": "0.7.5-labs.ff2ff30",
|
|
70
|
+
"@dxos/context": "0.7.5-labs.ff2ff30",
|
|
71
|
+
"@dxos/client": "0.7.5-labs.ff2ff30",
|
|
72
|
+
"@dxos/echo-db": "0.7.5-labs.ff2ff30",
|
|
73
|
+
"@dxos/crypto": "0.7.5-labs.ff2ff30",
|
|
74
|
+
"@dxos/echo-protocol": "0.7.5-labs.ff2ff30",
|
|
75
|
+
"@dxos/edge-client": "0.7.5-labs.ff2ff30",
|
|
76
|
+
"@dxos/keys": "0.7.5-labs.ff2ff30",
|
|
77
|
+
"@dxos/echo-schema": "0.7.5-labs.ff2ff30",
|
|
78
|
+
"@dxos/live-object": "0.7.5-labs.ff2ff30",
|
|
79
|
+
"@dxos/log": "0.7.5-labs.ff2ff30",
|
|
80
|
+
"@dxos/node-std": "0.7.5-labs.ff2ff30",
|
|
81
|
+
"@dxos/protocols": "0.7.5-labs.ff2ff30",
|
|
82
|
+
"@dxos/invariant": "0.7.5-labs.ff2ff30",
|
|
83
|
+
"@dxos/schema": "0.7.5-labs.ff2ff30",
|
|
84
|
+
"@dxos/util": "0.7.5-labs.ff2ff30"
|
|
85
85
|
},
|
|
86
86
|
"devDependencies": {
|
|
87
87
|
"@types/express": "^4.17.17",
|
|
88
88
|
"@types/ws": "^7.4.0",
|
|
89
|
-
"@dxos/agent": "0.7.5-labs.
|
|
89
|
+
"@dxos/agent": "0.7.5-labs.ff2ff30"
|
|
90
90
|
},
|
|
91
91
|
"publishConfig": {
|
|
92
92
|
"access": "public"
|
|
@@ -19,18 +19,20 @@ describe('Bundler', () => {
|
|
|
19
19
|
|
|
20
20
|
test('Basic', async () => {
|
|
21
21
|
const bundler = new Bundler({ platform: 'node', sandboxedModules: [], remoteModules: {} });
|
|
22
|
-
const result = await bundler.bundle('const x = 100'); // TODO(burdon): Test import.
|
|
22
|
+
const result = await bundler.bundle({ source: 'const x = 100' }); // TODO(burdon): Test import.
|
|
23
23
|
expect(result.bundle).to.exist;
|
|
24
24
|
expect(result.error).to.not.exist;
|
|
25
25
|
});
|
|
26
26
|
|
|
27
27
|
test('Import', async () => {
|
|
28
28
|
const bundler = new Bundler({ platform: 'node', sandboxedModules: [], remoteModules: {} });
|
|
29
|
-
const result = await bundler.bundle(
|
|
29
|
+
const result = await bundler.bundle({
|
|
30
|
+
source: `
|
|
30
31
|
import { Filter } from './runtime.js';
|
|
31
32
|
|
|
32
33
|
const query = Filter.typename('dxos.org/type/Example');
|
|
33
|
-
|
|
34
|
+
`,
|
|
35
|
+
});
|
|
34
36
|
expect(result.bundle).to.exist;
|
|
35
37
|
expect(result.error).to.not.exist;
|
|
36
38
|
});
|
|
@@ -38,17 +40,19 @@ describe('Bundler', () => {
|
|
|
38
40
|
// TODO(dmaretskyi): Flaky on CI: https://cloud.nx.app/runs/Hjcifa8Ccq/task/plugin-script%3Atest
|
|
39
41
|
test.skip('HTTPS Import', async () => {
|
|
40
42
|
const bundler = new Bundler({ platform: 'node', sandboxedModules: [], remoteModules: {} });
|
|
41
|
-
const result = await bundler.bundle(
|
|
43
|
+
const result = await bundler.bundle({
|
|
44
|
+
source: `
|
|
42
45
|
import { invariant } from 'https://esm.sh/@dxos/invariant';
|
|
43
46
|
invariant(true);
|
|
44
|
-
|
|
47
|
+
`,
|
|
48
|
+
});
|
|
45
49
|
expect(result.bundle).to.exist;
|
|
46
50
|
expect(result.error).to.not.exist;
|
|
47
51
|
});
|
|
48
52
|
|
|
49
53
|
test('Error', async () => {
|
|
50
54
|
const bundler = new Bundler({ platform: 'node', sandboxedModules: [], remoteModules: {} });
|
|
51
|
-
const result = await bundler.bundle("import missing from './module'; missing();");
|
|
55
|
+
const result = await bundler.bundle({ source: "import missing from './module'; missing();" });
|
|
52
56
|
expect(result.bundle).to.not.exist;
|
|
53
57
|
expect(result.error).to.exist;
|
|
54
58
|
});
|
package/src/bundler/bundler.ts
CHANGED
|
@@ -15,9 +15,23 @@ export type Import = {
|
|
|
15
15
|
namedImports: string[];
|
|
16
16
|
};
|
|
17
17
|
|
|
18
|
-
export type
|
|
18
|
+
export type BundleOptions = {
|
|
19
|
+
/**
|
|
20
|
+
* Path to the source file on the local file system.
|
|
21
|
+
* If provided, the path will be used instead of the `source` code.
|
|
22
|
+
*/
|
|
23
|
+
path?: string;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Source code to bundle.
|
|
27
|
+
* Required if `path` is not provided.
|
|
28
|
+
*/
|
|
29
|
+
source?: string;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export type BundleResult = {
|
|
19
33
|
timestamp: number;
|
|
20
|
-
sourceHash
|
|
34
|
+
sourceHash?: Buffer;
|
|
21
35
|
imports?: Import[];
|
|
22
36
|
bundle?: string;
|
|
23
37
|
error?: any;
|
|
@@ -42,13 +56,13 @@ export const initializeBundler = async (options: { wasmUrl: string }) => {
|
|
|
42
56
|
export class Bundler {
|
|
43
57
|
constructor(private readonly _options: BundlerOptions) {}
|
|
44
58
|
|
|
45
|
-
async bundle(source:
|
|
59
|
+
async bundle({ path, source }: BundleOptions): Promise<BundleResult> {
|
|
46
60
|
const { sandboxedModules: providedModules, ...options } = this._options;
|
|
47
61
|
|
|
48
|
-
const createResult = async (result?: Partial<
|
|
62
|
+
const createResult = async (result?: Partial<BundleResult>) => {
|
|
49
63
|
return {
|
|
50
64
|
timestamp: Date.now(),
|
|
51
|
-
sourceHash: Buffer.from(await subtleCrypto.digest('SHA-256', Buffer.from(source))),
|
|
65
|
+
sourceHash: source ? Buffer.from(await subtleCrypto.digest('SHA-256', Buffer.from(source))) : undefined,
|
|
52
66
|
...result,
|
|
53
67
|
};
|
|
54
68
|
};
|
|
@@ -58,7 +72,7 @@ export class Bundler {
|
|
|
58
72
|
await initialized;
|
|
59
73
|
}
|
|
60
74
|
|
|
61
|
-
const imports = analyzeSourceFileImports(source);
|
|
75
|
+
const imports = source ? analyzeSourceFileImports(source) : [];
|
|
62
76
|
|
|
63
77
|
// https://esbuild.github.io/api/#build
|
|
64
78
|
try {
|
|
@@ -67,7 +81,7 @@ export class Bundler {
|
|
|
67
81
|
conditions: ['workerd', 'browser'],
|
|
68
82
|
metafile: true,
|
|
69
83
|
write: false,
|
|
70
|
-
entryPoints: ['memory:main.tsx'],
|
|
84
|
+
entryPoints: [path ?? 'memory:main.tsx'],
|
|
71
85
|
bundle: true,
|
|
72
86
|
format: 'esm',
|
|
73
87
|
plugins: [
|