devflare 1.0.0-next.13 → 1.0.0-next.14
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/{build-e6kgjwr8.js → build-n639efmn.js} +1 -1
- package/dist/bundler/do-bundler.d.ts.map +1 -1
- package/dist/bundler/worker-bundler.d.ts.map +1 -1
- package/dist/bundler/worker-compat.d.ts +4 -0
- package/dist/bundler/worker-compat.d.ts.map +1 -0
- package/dist/{deploy-eeaqwxaa.js → deploy-zvnq6xh7.js} +1 -1
- package/dist/{dev-mqsffeeb.js → dev-c1xc1gq9.js} +1 -1
- package/dist/{index-nb0bqtx7.js → index-001mw014.js} +308 -2
- package/dist/{index-8x16kn47.js → index-f4q0jbnj.js} +3 -3
- package/dist/src/cli/index.js +1 -1
- package/dist/src/index.js +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"do-bundler.d.ts","sourceRoot":"","sources":["../../src/bundler/do-bundler.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAS9C,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAA;
|
|
1
|
+
{"version":3,"file":"do-bundler.d.ts","sourceRoot":"","sources":["../../src/bundler/do-bundler.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAS9C,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAA;AAa/D,MAAM,WAAW,gBAAgB;IAChC,6BAA6B;IAC7B,GAAG,EAAE,MAAM,CAAA;IACX,sDAAsD;IACtD,OAAO,EAAE,MAAM,CAAA;IACf,yCAAyC;IACzC,MAAM,EAAE,MAAM,CAAA;IACd,8DAA8D;IAC9D,eAAe,CAAC,EAAE,uBAAuB,CAAA;IACzC,qDAAqD;IACrD,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,uDAAuD;IACvD,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,sBAAsB;IACtB,MAAM,CAAC,EAAE,eAAe,CAAA;IACxB,oCAAoC;IACpC,SAAS,CAAC,EAAE,CAAC,MAAM,EAAE,cAAc,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;CAC5D;AAED,MAAM,WAAW,cAAc;IAC9B,gDAA8C;IAC9C,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC5B,yCAAuC;IACvC,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC5B,+CAA6C;IAC7C,WAAW,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAA;IAClC,6BAA6B;IAC7B,MAAM,EAAE,KAAK,EAAE,CAAA;CACf;AAED,MAAM,WAAW,SAAS;IACzB,+BAA+B;IAC/B,KAAK,IAAI,OAAO,CAAC,cAAc,CAAC,CAAA;IAChC,iCAAiC;IACjC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;IACtB,oBAAoB;IACpB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;IACtB,mCAAmC;IACnC,SAAS,IAAI,cAAc,CAAA;CAC3B;AAkbD;;GAEG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,gBAAgB,GAAG,SAAS,CAgOpE;AAMD;;GAEG;AACH,wBAAsB,SAAS,CAAC,OAAO,EAAE,IAAI,CAAC,gBAAgB,EAAE,WAAW,CAAC,GAAG,OAAO,CAAC,cAAc,CAAC,CAIrG"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker-bundler.d.ts","sourceRoot":"","sources":["../../src/bundler/worker-bundler.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAQ9C,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAA;
|
|
1
|
+
{"version":3,"file":"worker-bundler.d.ts","sourceRoot":"","sources":["../../src/bundler/worker-bundler.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAQ9C,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAA;AAM/D,MAAM,WAAW,oBAAoB;IACpC,GAAG,EAAE,MAAM,CAAA;IACX,SAAS,EAAE,MAAM,CAAA;IACjB,OAAO,EAAE,MAAM,CAAA;IACf,eAAe,CAAC,EAAE,uBAAuB,CAAA;IACzC,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,MAAM,CAAC,EAAE,eAAe,CAAA;CACxB;AAwOD,wBAAsB,iBAAiB,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,MAAM,CAAC,CAiCtF"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Plugin as RolldownPlugin } from 'rolldown';
|
|
2
|
+
export declare function assertWorkerBundleHasNoDynamicImports(bundlePath: string): Promise<void>;
|
|
3
|
+
export declare function createWorkerDynamicImportPlugin(): RolldownPlugin;
|
|
4
|
+
//# sourceMappingURL=worker-compat.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker-compat.d.ts","sourceRoot":"","sources":["../../src/bundler/worker-compat.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,cAAc,EAAE,MAAM,UAAU,CAAA;AA0ZxD,wBAAsB,qCAAqC,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CA8B7F;AAED,wBAAgB,+BAA+B,IAAI,cAAc,CAQhE"}
|
|
@@ -12,6 +12,310 @@ import {
|
|
|
12
12
|
// src/bundler/worker-bundler.ts
|
|
13
13
|
import { fileURLToPath } from "node:url";
|
|
14
14
|
import { dirname, resolve } from "pathe";
|
|
15
|
+
|
|
16
|
+
// src/bundler/worker-compat.ts
|
|
17
|
+
import MagicString from "magic-string";
|
|
18
|
+
import ts from "typescript";
|
|
19
|
+
var WORKER_DYNAMIC_IMPORT_ERROR = "Devflare worker bundles cannot contain unresolved dynamic import() expressions because Miniflare/workerd reject dynamic module specifiers";
|
|
20
|
+
function getScriptKind(id) {
|
|
21
|
+
if (id.endsWith(".tsx")) {
|
|
22
|
+
return ts.ScriptKind.TSX;
|
|
23
|
+
}
|
|
24
|
+
if (id.endsWith(".ts") || id.endsWith(".mts") || id.endsWith(".cts")) {
|
|
25
|
+
return ts.ScriptKind.TS;
|
|
26
|
+
}
|
|
27
|
+
if (id.endsWith(".jsx")) {
|
|
28
|
+
return ts.ScriptKind.JSX;
|
|
29
|
+
}
|
|
30
|
+
return ts.ScriptKind.JS;
|
|
31
|
+
}
|
|
32
|
+
function createSourceFile(code, id) {
|
|
33
|
+
return ts.createSourceFile(id, code, ts.ScriptTarget.Latest, true, getScriptKind(id));
|
|
34
|
+
}
|
|
35
|
+
function hasExportModifier(node) {
|
|
36
|
+
if (!ts.canHaveModifiers(node)) {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
return ts.getModifiers(node)?.some((modifier) => modifier.kind === ts.SyntaxKind.ExportKeyword) ?? false;
|
|
40
|
+
}
|
|
41
|
+
function isConstVariableStatement(statement) {
|
|
42
|
+
return ts.isVariableStatement(statement) && (statement.declarationList.flags & ts.NodeFlags.Const) !== 0;
|
|
43
|
+
}
|
|
44
|
+
function quoteString(value) {
|
|
45
|
+
return `'${value.replace(/\\/g, "\\\\").replace(/'/g, `\\'`)}'`;
|
|
46
|
+
}
|
|
47
|
+
function resolveLiteralImportSpecifier(expression, constStrings) {
|
|
48
|
+
if (ts.isStringLiteral(expression) || ts.isNoSubstitutionTemplateLiteral(expression)) {
|
|
49
|
+
return expression.text;
|
|
50
|
+
}
|
|
51
|
+
if (ts.isParenthesizedExpression(expression)) {
|
|
52
|
+
return resolveLiteralImportSpecifier(expression.expression, constStrings);
|
|
53
|
+
}
|
|
54
|
+
if (ts.isIdentifier(expression)) {
|
|
55
|
+
return constStrings.get(expression.text) ?? null;
|
|
56
|
+
}
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
function collectTopLevelConstStrings(sourceFile) {
|
|
60
|
+
const constStrings = new Map;
|
|
61
|
+
for (const statement of sourceFile.statements) {
|
|
62
|
+
if (!isConstVariableStatement(statement)) {
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
for (const declaration of statement.declarationList.declarations) {
|
|
66
|
+
if (!ts.isIdentifier(declaration.name) || !declaration.initializer) {
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
const literal = resolveLiteralImportSpecifier(declaration.initializer, constStrings);
|
|
70
|
+
if (literal !== null) {
|
|
71
|
+
constStrings.set(declaration.name.text, literal);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return constStrings;
|
|
76
|
+
}
|
|
77
|
+
function unwrapDynamicImportExpression(expression) {
|
|
78
|
+
if (ts.isParenthesizedExpression(expression)) {
|
|
79
|
+
return unwrapDynamicImportExpression(expression.expression);
|
|
80
|
+
}
|
|
81
|
+
if (ts.isAwaitExpression(expression)) {
|
|
82
|
+
return unwrapDynamicImportExpression(expression.expression);
|
|
83
|
+
}
|
|
84
|
+
if (!ts.isCallExpression(expression) || expression.expression.kind !== ts.SyntaxKind.ImportKeyword) {
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
return expression;
|
|
88
|
+
}
|
|
89
|
+
function getWrapperBodyExpression(body) {
|
|
90
|
+
if (!body) {
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
if (!ts.isBlock(body)) {
|
|
94
|
+
return body;
|
|
95
|
+
}
|
|
96
|
+
if (body.statements.length !== 1) {
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
const [statement] = body.statements;
|
|
100
|
+
if (!ts.isReturnStatement(statement) || !statement.expression) {
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
return statement.expression;
|
|
104
|
+
}
|
|
105
|
+
function createImportWrapper(name, parameterName, body, sourceFile) {
|
|
106
|
+
const bodyExpression = getWrapperBodyExpression(body);
|
|
107
|
+
if (!bodyExpression) {
|
|
108
|
+
return null;
|
|
109
|
+
}
|
|
110
|
+
const importExpression = unwrapDynamicImportExpression(bodyExpression);
|
|
111
|
+
if (!importExpression || importExpression.arguments.length < 1) {
|
|
112
|
+
return null;
|
|
113
|
+
}
|
|
114
|
+
const [importArgument] = importExpression.arguments;
|
|
115
|
+
if (!ts.isIdentifier(importArgument) || importArgument.text !== parameterName || !body) {
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
return {
|
|
119
|
+
name,
|
|
120
|
+
parameterName,
|
|
121
|
+
bodyStart: body.getStart(sourceFile),
|
|
122
|
+
bodyEnd: body.getEnd(),
|
|
123
|
+
specifiers: new Set,
|
|
124
|
+
hasUnsupportedCalls: false
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
function collectImportWrappers(sourceFile) {
|
|
128
|
+
const wrappers = new Map;
|
|
129
|
+
for (const statement of sourceFile.statements) {
|
|
130
|
+
if (ts.isFunctionDeclaration(statement) && statement.name && !hasExportModifier(statement) && statement.parameters.length === 1 && ts.isIdentifier(statement.parameters[0]?.name)) {
|
|
131
|
+
const wrapper = createImportWrapper(statement.name.text, statement.parameters[0].name.text, statement.body, sourceFile);
|
|
132
|
+
if (wrapper) {
|
|
133
|
+
wrappers.set(wrapper.name, wrapper);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
if (!isConstVariableStatement(statement) || hasExportModifier(statement)) {
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
for (const declaration of statement.declarationList.declarations) {
|
|
140
|
+
if (!ts.isIdentifier(declaration.name) || !declaration.initializer) {
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
if (!ts.isArrowFunction(declaration.initializer) && !ts.isFunctionExpression(declaration.initializer)) {
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
146
|
+
if (declaration.initializer.parameters.length !== 1 || !ts.isIdentifier(declaration.initializer.parameters[0]?.name)) {
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
const wrapper = createImportWrapper(declaration.name.text, declaration.initializer.parameters[0].name.text, declaration.initializer.body, sourceFile);
|
|
150
|
+
if (wrapper) {
|
|
151
|
+
wrappers.set(wrapper.name, wrapper);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return wrappers;
|
|
156
|
+
}
|
|
157
|
+
function collectWrapperCallSpecifiers(sourceFile, wrappers, constStrings) {
|
|
158
|
+
function visit(node) {
|
|
159
|
+
if (ts.isCallExpression(node) && ts.isIdentifier(node.expression)) {
|
|
160
|
+
const wrapper = wrappers.get(node.expression.text);
|
|
161
|
+
if (wrapper) {
|
|
162
|
+
if (node.arguments.length !== 1) {
|
|
163
|
+
wrapper.hasUnsupportedCalls = true;
|
|
164
|
+
} else {
|
|
165
|
+
const specifier = resolveLiteralImportSpecifier(node.arguments[0], constStrings);
|
|
166
|
+
if (specifier === null) {
|
|
167
|
+
wrapper.hasUnsupportedCalls = true;
|
|
168
|
+
} else {
|
|
169
|
+
wrapper.specifiers.add(specifier);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
ts.forEachChild(node, visit);
|
|
175
|
+
}
|
|
176
|
+
visit(sourceFile);
|
|
177
|
+
}
|
|
178
|
+
function createImportIdentifier(specifierToIdentifier, specifier) {
|
|
179
|
+
const existing = specifierToIdentifier.get(specifier);
|
|
180
|
+
if (existing) {
|
|
181
|
+
return existing;
|
|
182
|
+
}
|
|
183
|
+
const identifier = `__devflareDynamicImport${specifierToIdentifier.size}`;
|
|
184
|
+
specifierToIdentifier.set(specifier, identifier);
|
|
185
|
+
return identifier;
|
|
186
|
+
}
|
|
187
|
+
function buildWrapperBody(wrapper, specifierToIdentifier) {
|
|
188
|
+
const cases = Array.from(wrapper.specifiers).sort((left, right) => left.localeCompare(right)).map((specifier) => {
|
|
189
|
+
const identifier = createImportIdentifier(specifierToIdentifier, specifier);
|
|
190
|
+
return ` case ${quoteString(specifier)}:
|
|
191
|
+
return Promise.resolve(${identifier})`;
|
|
192
|
+
}).join(`
|
|
193
|
+
`);
|
|
194
|
+
return `{
|
|
195
|
+
switch (${wrapper.parameterName}) {
|
|
196
|
+
${cases}
|
|
197
|
+
default:
|
|
198
|
+
return Promise.reject(new Error(\`Unsupported dynamic import in Devflare worker bundle: \${${wrapper.parameterName}}\`))
|
|
199
|
+
}
|
|
200
|
+
}`;
|
|
201
|
+
}
|
|
202
|
+
function findContainingWrapper(callExpression, wrappers, sourceFile) {
|
|
203
|
+
const start = callExpression.getStart(sourceFile);
|
|
204
|
+
const end = callExpression.getEnd();
|
|
205
|
+
for (const wrapper of wrappers) {
|
|
206
|
+
if (start >= wrapper.bodyStart && end <= wrapper.bodyEnd) {
|
|
207
|
+
return wrapper;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
return null;
|
|
211
|
+
}
|
|
212
|
+
function transformWorkerDynamicImports(code, id) {
|
|
213
|
+
const sourceFile = createSourceFile(code, id);
|
|
214
|
+
const constStrings = collectTopLevelConstStrings(sourceFile);
|
|
215
|
+
const wrappers = collectImportWrappers(sourceFile);
|
|
216
|
+
collectWrapperCallSpecifiers(sourceFile, wrappers, constStrings);
|
|
217
|
+
const transformableWrappers = Array.from(wrappers.values()).filter((wrapper) => {
|
|
218
|
+
return !wrapper.hasUnsupportedCalls && wrapper.specifiers.size > 0;
|
|
219
|
+
});
|
|
220
|
+
const replacements = [];
|
|
221
|
+
const specifierToIdentifier = new Map;
|
|
222
|
+
function visit(node) {
|
|
223
|
+
if (ts.isCallExpression(node) && node.expression.kind === ts.SyntaxKind.ImportKeyword) {
|
|
224
|
+
const containingWrapper = findContainingWrapper(node, transformableWrappers, sourceFile);
|
|
225
|
+
if (containingWrapper && node.arguments.length === 1 && ts.isIdentifier(node.arguments[0]) && node.arguments[0].text === containingWrapper.parameterName) {
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
const [argument] = node.arguments;
|
|
229
|
+
if (!argument) {
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
const specifier = resolveLiteralImportSpecifier(argument, constStrings);
|
|
233
|
+
if (specifier !== null) {
|
|
234
|
+
replacements.push({
|
|
235
|
+
start: node.getStart(sourceFile),
|
|
236
|
+
end: node.getEnd(),
|
|
237
|
+
text: `Promise.resolve(${createImportIdentifier(specifierToIdentifier, specifier)})`
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
ts.forEachChild(node, visit);
|
|
242
|
+
}
|
|
243
|
+
visit(sourceFile);
|
|
244
|
+
if (replacements.length === 0 && transformableWrappers.length === 0) {
|
|
245
|
+
return null;
|
|
246
|
+
}
|
|
247
|
+
const s = new MagicString(code);
|
|
248
|
+
for (const replacement of replacements.sort((left, right) => right.start - left.start)) {
|
|
249
|
+
s.overwrite(replacement.start, replacement.end, replacement.text);
|
|
250
|
+
}
|
|
251
|
+
for (const wrapper of transformableWrappers.sort((left, right) => right.bodyStart - left.bodyStart)) {
|
|
252
|
+
s.overwrite(wrapper.bodyStart, wrapper.bodyEnd, buildWrapperBody(wrapper, specifierToIdentifier));
|
|
253
|
+
}
|
|
254
|
+
if (specifierToIdentifier.size > 0) {
|
|
255
|
+
const importBlock = Array.from(specifierToIdentifier.entries()).map(([specifier, identifier]) => `import * as ${identifier} from ${quoteString(specifier)}`).join(`
|
|
256
|
+
`);
|
|
257
|
+
const importInsertPosition = code.startsWith("#!") ? code.indexOf(`
|
|
258
|
+
`) === -1 ? code.length : code.indexOf(`
|
|
259
|
+
`) + 1 : 0;
|
|
260
|
+
s.appendLeft(importInsertPosition, `${importBlock}
|
|
261
|
+
`);
|
|
262
|
+
}
|
|
263
|
+
return {
|
|
264
|
+
code: s.toString(),
|
|
265
|
+
map: s.generateMap({
|
|
266
|
+
source: id,
|
|
267
|
+
file: `${id}.map`,
|
|
268
|
+
includeContent: true
|
|
269
|
+
})
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
function findDynamicImportCalls(sourceFile) {
|
|
273
|
+
const calls = [];
|
|
274
|
+
function visit(node) {
|
|
275
|
+
if (ts.isCallExpression(node) && node.expression.kind === ts.SyntaxKind.ImportKeyword) {
|
|
276
|
+
calls.push(node);
|
|
277
|
+
}
|
|
278
|
+
ts.forEachChild(node, visit);
|
|
279
|
+
}
|
|
280
|
+
visit(sourceFile);
|
|
281
|
+
return calls;
|
|
282
|
+
}
|
|
283
|
+
async function assertWorkerBundleHasNoDynamicImports(bundlePath) {
|
|
284
|
+
const fs = await import("node:fs/promises");
|
|
285
|
+
const code = await fs.readFile(bundlePath, "utf-8");
|
|
286
|
+
const sourceFile = createSourceFile(code, bundlePath);
|
|
287
|
+
const dynamicImports = findDynamicImportCalls(sourceFile);
|
|
288
|
+
if (dynamicImports.length === 0) {
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
291
|
+
const examples = dynamicImports.slice(0, 3).map((callExpression) => {
|
|
292
|
+
const start = callExpression.getStart(sourceFile);
|
|
293
|
+
const { line, character } = sourceFile.getLineAndCharacterOfPosition(start);
|
|
294
|
+
const snippet = code.slice(start, callExpression.getEnd()).replace(/\s+/g, " ").trim();
|
|
295
|
+
return `- ${line + 1}:${character + 1} ${snippet}`;
|
|
296
|
+
}).join(`
|
|
297
|
+
`);
|
|
298
|
+
throw new Error([
|
|
299
|
+
WORKER_DYNAMIC_IMPORT_ERROR,
|
|
300
|
+
`Bundle: ${bundlePath}`,
|
|
301
|
+
`Examples:
|
|
302
|
+
${examples}`,
|
|
303
|
+
"Devflare can normalize literal import() calls and simple helper wrappers whose call sites are literal strings, but truly runtime-computed specifiers must be converted to static imports for worker bundles."
|
|
304
|
+
].join(`
|
|
305
|
+
|
|
306
|
+
`));
|
|
307
|
+
}
|
|
308
|
+
function createWorkerDynamicImportPlugin() {
|
|
309
|
+
return {
|
|
310
|
+
name: "devflare-worker-dynamic-imports",
|
|
311
|
+
transform(code, id) {
|
|
312
|
+
const result = transformWorkerDynamicImports(code, id);
|
|
313
|
+
return result ?? null;
|
|
314
|
+
}
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
// src/bundler/worker-bundler.ts
|
|
15
319
|
function toArray(value) {
|
|
16
320
|
return Array.isArray(value) ? value : [value];
|
|
17
321
|
}
|
|
@@ -176,7 +480,7 @@ function resolveWorkerRolldownConfig(options) {
|
|
|
176
480
|
target: userTarget ?? options.target,
|
|
177
481
|
tsconfig: userTsconfig ?? resolve(options.cwd, "tsconfig.json"),
|
|
178
482
|
external: mergeExternalOptions(defaultExternalModules, userExternal),
|
|
179
|
-
plugins: mergePluginOptions(
|
|
483
|
+
plugins: mergePluginOptions(createWorkerDynamicImportPlugin(), userPlugins),
|
|
180
484
|
resolve: mergeResolveOptions({
|
|
181
485
|
alias: options.alias
|
|
182
486
|
}, userResolve)
|
|
@@ -214,6 +518,7 @@ async function bundleWorkerEntry(options) {
|
|
|
214
518
|
const bundle = await rolldown(inputOptions);
|
|
215
519
|
try {
|
|
216
520
|
await bundle.write(outputOptions);
|
|
521
|
+
await assertWorkerBundleHasNoDynamicImports(options.outFile);
|
|
217
522
|
} finally {
|
|
218
523
|
await bundle.close();
|
|
219
524
|
}
|
|
@@ -368,7 +673,7 @@ function resolveDOBundleRolldownConfig(options) {
|
|
|
368
673
|
platform: "neutral",
|
|
369
674
|
tsconfig: userTsconfig ?? resolve2(options.cwd, "tsconfig.json"),
|
|
370
675
|
external: mergeExternalOptions2(defaultExternalModules, userExternal),
|
|
371
|
-
plugins: mergePluginOptions2(
|
|
676
|
+
plugins: mergePluginOptions2(createWorkerDynamicImportPlugin(), userPlugins),
|
|
372
677
|
resolve: mergeResolveOptions2({
|
|
373
678
|
alias: {
|
|
374
679
|
debug: options.debugShimPath
|
|
@@ -437,6 +742,7 @@ export default createDebug
|
|
|
437
742
|
});
|
|
438
743
|
const bundle = await rolldown(inputOptions);
|
|
439
744
|
await bundle.write(outputOptions);
|
|
745
|
+
await assertWorkerBundleHasNoDynamicImports(outFile);
|
|
440
746
|
await bundle.close();
|
|
441
747
|
try {
|
|
442
748
|
await fs.unlink(tempFilePath);
|
|
@@ -160,15 +160,15 @@ async function runInit(parsed, logger, options) {
|
|
|
160
160
|
return runInitCommand(parsed, logger, options);
|
|
161
161
|
}
|
|
162
162
|
async function runDev(parsed, logger, options) {
|
|
163
|
-
const { runDevCommand } = await import("./dev-
|
|
163
|
+
const { runDevCommand } = await import("./dev-c1xc1gq9.js");
|
|
164
164
|
return runDevCommand(parsed, logger, options);
|
|
165
165
|
}
|
|
166
166
|
async function runBuild(parsed, logger, options) {
|
|
167
|
-
const { runBuildCommand } = await import("./build-
|
|
167
|
+
const { runBuildCommand } = await import("./build-n639efmn.js");
|
|
168
168
|
return runBuildCommand(parsed, logger, options);
|
|
169
169
|
}
|
|
170
170
|
async function runDeploy(parsed, logger, options) {
|
|
171
|
-
const { runDeployCommand } = await import("./deploy-
|
|
171
|
+
const { runDeployCommand } = await import("./deploy-zvnq6xh7.js");
|
|
172
172
|
return runDeployCommand(parsed, logger, options);
|
|
173
173
|
}
|
|
174
174
|
async function runTypes(parsed, logger, options) {
|
package/dist/src/cli/index.js
CHANGED
package/dist/src/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "devflare",
|
|
3
|
-
"version": "1.0.0-next.
|
|
3
|
+
"version": "1.0.0-next.14",
|
|
4
4
|
"description": "Devflare is a developer-first toolkit for Cloudflare Workers that sits on top of Miniflare and Wrangler-compatible config",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/src/index.js",
|