@quilted/rollup 0.1.19 → 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/CHANGELOG.md +19 -0
- package/build/esm/app.mjs +443 -219
- package/build/esm/constants.mjs +5 -5
- package/build/esm/features/assets.mjs +93 -81
- package/build/esm/features/async.mjs +186 -0
- package/build/esm/features/css.mjs +26 -39
- package/build/esm/features/env.mjs +47 -44
- package/build/esm/features/esnext.mjs +57 -0
- package/build/esm/features/graphql/transform.mjs +60 -56
- package/build/esm/features/graphql.mjs +65 -47
- package/build/esm/features/request-router.mjs +6 -4
- package/build/esm/features/source-code.mjs +54 -28
- package/build/esm/features/system-js.mjs +13 -18
- package/build/esm/features/typescript.mjs +13 -10
- package/build/esm/features/workers.mjs +173 -0
- package/build/esm/index.mjs +3 -2
- package/build/esm/module.mjs +69 -62
- package/build/esm/package.mjs +275 -84
- package/build/esm/server.mjs +118 -0
- package/build/esm/shared/browserslist.mjs +141 -16
- package/build/esm/shared/magic-module.mjs +9 -7
- package/build/esm/shared/package-json.mjs +7 -1
- package/build/esm/shared/path.mjs +7 -0
- package/build/esm/shared/rollup.mjs +89 -25
- package/build/esm/shared/strings.mjs +7 -6
- package/build/tsconfig.tsbuildinfo +1 -1
- package/build/typescript/app.d.ts +126 -27
- package/build/typescript/app.d.ts.map +1 -1
- package/build/typescript/features/assets.d.ts +1 -2
- package/build/typescript/features/assets.d.ts.map +1 -1
- package/build/typescript/features/async.d.ts +10 -0
- package/build/typescript/features/async.d.ts.map +1 -0
- package/build/typescript/features/css.d.ts +2 -1
- package/build/typescript/features/css.d.ts.map +1 -1
- package/build/typescript/features/env.d.ts +1 -0
- package/build/typescript/features/env.d.ts.map +1 -1
- package/build/typescript/features/esnext.d.ts +9 -0
- package/build/typescript/features/esnext.d.ts.map +1 -0
- package/build/typescript/features/graphql.d.ts +2 -2
- package/build/typescript/features/graphql.d.ts.map +1 -1
- package/build/typescript/features/source-code.d.ts +9 -3
- package/build/typescript/features/source-code.d.ts.map +1 -1
- package/build/typescript/features/workers.d.ts +52 -0
- package/build/typescript/features/workers.d.ts.map +1 -0
- package/build/typescript/index.d.ts +3 -2
- package/build/typescript/index.d.ts.map +1 -1
- package/build/typescript/module.d.ts +24 -6
- package/build/typescript/module.d.ts.map +1 -1
- package/build/typescript/package.d.ts +196 -4
- package/build/typescript/package.d.ts.map +1 -1
- package/build/typescript/server.d.ts +98 -0
- package/build/typescript/server.d.ts.map +1 -0
- package/build/typescript/shared/browserslist.d.ts +20 -3
- package/build/typescript/shared/browserslist.d.ts.map +1 -1
- package/build/typescript/shared/path.d.ts +2 -0
- package/build/typescript/shared/path.d.ts.map +1 -0
- package/build/typescript/shared/rollup.d.ts +27 -1
- package/build/typescript/shared/rollup.d.ts.map +1 -1
- package/configuration/rollup.config.js +40 -0
- package/package.json +61 -8
- package/source/app.ts +466 -96
- package/source/features/assets.ts +5 -7
- package/source/features/async.ts +249 -0
- package/source/features/css.ts +4 -2
- package/source/features/env.ts +6 -0
- package/source/features/esnext.ts +70 -0
- package/source/features/graphql.ts +4 -2
- package/source/features/source-code.ts +26 -8
- package/source/features/workers.ts +292 -0
- package/source/index.ts +4 -0
- package/source/module.ts +45 -19
- package/source/package.ts +394 -36
- package/source/server.ts +245 -0
- package/source/shared/browserslist.ts +208 -18
- package/source/shared/path.ts +5 -0
- package/source/shared/rollup.ts +102 -4
- package/tsconfig.json +6 -2
- package/build/cjs/app.cjs +0 -441
- package/build/cjs/constants.cjs +0 -13
- package/build/cjs/features/assets.cjs +0 -240
- package/build/cjs/features/css.cjs +0 -71
- package/build/cjs/features/env.cjs +0 -135
- package/build/cjs/features/graphql/transform.cjs +0 -186
- package/build/cjs/features/graphql.cjs +0 -86
- package/build/cjs/features/request-router.cjs +0 -31
- package/build/cjs/features/source-code.cjs +0 -54
- package/build/cjs/features/system-js.cjs +0 -36
- package/build/cjs/features/typescript.cjs +0 -56
- package/build/cjs/index.cjs +0 -13
- package/build/cjs/module.cjs +0 -121
- package/build/cjs/package.cjs +0 -170
- package/build/cjs/shared/browserslist.cjs +0 -25
- package/build/cjs/shared/magic-module.cjs +0 -32
- package/build/cjs/shared/package-json.cjs +0 -31
- package/build/cjs/shared/rollup.cjs +0 -72
- package/build/cjs/shared/strings.cjs +0 -16
- package/build/esnext/app.esnext +0 -414
- package/build/esnext/constants.esnext +0 -7
- package/build/esnext/features/assets.esnext +0 -215
- package/build/esnext/features/css.esnext +0 -69
- package/build/esnext/features/env.esnext +0 -112
- package/build/esnext/features/graphql/transform.esnext +0 -181
- package/build/esnext/features/graphql.esnext +0 -84
- package/build/esnext/features/request-router.esnext +0 -29
- package/build/esnext/features/source-code.esnext +0 -51
- package/build/esnext/features/system-js.esnext +0 -33
- package/build/esnext/features/typescript.esnext +0 -34
- package/build/esnext/index.esnext +0 -3
- package/build/esnext/module.esnext +0 -100
- package/build/esnext/package.esnext +0 -148
- package/build/esnext/shared/browserslist.esnext +0 -23
- package/build/esnext/shared/magic-module.esnext +0 -30
- package/build/esnext/shared/package-json.esnext +0 -10
- package/build/esnext/shared/rollup.esnext +0 -49
- package/build/esnext/shared/strings.esnext +0 -14
- package/build/typescript/env.d.ts +0 -55
- package/build/typescript/env.d.ts.map +0 -1
- package/build/typescript/graphql/transform.d.ts +0 -17
- package/build/typescript/graphql/transform.d.ts.map +0 -1
- package/build/typescript/graphql.d.ts +0 -6
- package/build/typescript/graphql.d.ts.map +0 -1
- package/build/typescript/request-router.d.ts +0 -15
- package/build/typescript/request-router.d.ts.map +0 -1
- package/build/typescript/shared/source-code.d.ts +0 -5
- package/build/typescript/shared/source-code.d.ts.map +0 -1
- package/quilt.project.ts +0 -5
|
@@ -6,46 +6,72 @@ const require = createRequire(import.meta.url);
|
|
|
6
6
|
function sourceCode({
|
|
7
7
|
mode,
|
|
8
8
|
targets,
|
|
9
|
+
react = true,
|
|
9
10
|
babel: useBabel = true
|
|
10
11
|
}) {
|
|
11
12
|
if (!useBabel) {
|
|
12
13
|
return esbuild({
|
|
13
14
|
// Support very modern features
|
|
14
|
-
target:
|
|
15
|
-
jsx:
|
|
16
|
-
jsxImportSource:
|
|
17
|
-
exclude:
|
|
15
|
+
target: "es2022",
|
|
16
|
+
jsx: "automatic",
|
|
17
|
+
jsxImportSource: "react",
|
|
18
|
+
exclude: "node_modules/**"
|
|
18
19
|
});
|
|
19
20
|
}
|
|
20
|
-
|
|
21
|
+
const babelOverride = typeof useBabel === "boolean" ? {} : useBabel;
|
|
22
|
+
const useBuiltIns = babelOverride.useBuiltIns;
|
|
23
|
+
let babelOptions = {
|
|
21
24
|
envName: mode,
|
|
22
25
|
configFile: false,
|
|
23
26
|
babelrc: false,
|
|
24
|
-
presets: [
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
27
|
+
presets: [
|
|
28
|
+
require.resolve("@babel/preset-typescript"),
|
|
29
|
+
[
|
|
30
|
+
require.resolve("@babel/preset-react"),
|
|
31
|
+
{
|
|
32
|
+
runtime: "automatic",
|
|
33
|
+
importSource: typeof react === "string" ? react : "react",
|
|
34
|
+
development: mode === "development"
|
|
35
|
+
}
|
|
36
|
+
],
|
|
37
|
+
[
|
|
38
|
+
require.resolve("@babel/preset-env"),
|
|
39
|
+
{
|
|
40
|
+
bugfixes: true,
|
|
41
|
+
shippedProposals: true,
|
|
42
|
+
useBuiltIns,
|
|
43
|
+
corejs: useBuiltIns ? 3 : void 0
|
|
44
|
+
// I thought I wanted this, but it seems to break the `targets` option
|
|
45
|
+
// passed as a root argument.
|
|
46
|
+
// ignoreBrowserslistConfig: targets != null,
|
|
47
|
+
}
|
|
48
|
+
]
|
|
49
|
+
],
|
|
50
|
+
plugins: [
|
|
51
|
+
[
|
|
52
|
+
require.resolve("@babel/plugin-proposal-decorators"),
|
|
53
|
+
{ version: "2023-01" }
|
|
54
|
+
]
|
|
55
|
+
],
|
|
56
|
+
extensions: [
|
|
57
|
+
".ts",
|
|
58
|
+
".tsx",
|
|
59
|
+
".mts",
|
|
60
|
+
".mtsx",
|
|
61
|
+
".js",
|
|
62
|
+
".jsx",
|
|
63
|
+
".es6",
|
|
64
|
+
".es",
|
|
65
|
+
".mjs"
|
|
66
|
+
],
|
|
67
|
+
exclude: "node_modules/**",
|
|
68
|
+
babelHelpers: "bundled",
|
|
43
69
|
skipPreflightCheck: true,
|
|
44
70
|
// Babel doesn’t like this option being set to `undefined`.
|
|
45
|
-
...
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
71
|
+
...targets ? { targets } : {}
|
|
72
|
+
};
|
|
73
|
+
babelOptions = babelOverride.options?.(babelOptions) ?? babelOptions;
|
|
74
|
+
return babel(babelOptions);
|
|
49
75
|
}
|
|
50
76
|
|
|
51
77
|
export { sourceCode };
|
|
@@ -1,28 +1,23 @@
|
|
|
1
1
|
import { readFile } from 'node:fs/promises';
|
|
2
2
|
import { createRequire } from 'node:module';
|
|
3
3
|
|
|
4
|
-
function systemJS({
|
|
5
|
-
minify = false
|
|
6
|
-
} = {}) {
|
|
4
|
+
function systemJS({ minify = false } = {}) {
|
|
7
5
|
return {
|
|
8
|
-
name:
|
|
6
|
+
name: "@quilted/system-js",
|
|
9
7
|
async renderChunk(_, chunk, options) {
|
|
10
|
-
if (options.format !==
|
|
8
|
+
if (options.format !== "system" || !chunk.isEntry)
|
|
9
|
+
return null;
|
|
11
10
|
const require = createRequire(import.meta.url);
|
|
12
|
-
const systemjs = minify ? require.resolve(
|
|
13
|
-
|
|
14
|
-
// We write the systemjs loader to a dedicated file, and we make it the
|
|
15
|
-
// "first import" of the chunk so that it is the first file listed in
|
|
16
|
-
// the manifest.
|
|
11
|
+
const systemjs = minify ? require.resolve("systemjs/dist/s.min.js") : require.resolve("systemjs/dist/s.js");
|
|
17
12
|
const fileHandle = this.emitFile({
|
|
18
|
-
type:
|
|
19
|
-
name:
|
|
20
|
-
source: (await readFile(systemjs, {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
13
|
+
type: "asset",
|
|
14
|
+
name: "loader.js",
|
|
15
|
+
source: (await readFile(systemjs, { encoding: "utf8" })).replace(
|
|
16
|
+
// Remove the source map comment, if it is present, because we don’t upload the
|
|
17
|
+
// sourcemap for this file.
|
|
18
|
+
/\n?[/][/]# sourceMappingURL=s.*\.map\n?$/,
|
|
19
|
+
""
|
|
20
|
+
)
|
|
26
21
|
});
|
|
27
22
|
chunk.imports.unshift(this.getFileName(fileHandle));
|
|
28
23
|
return null;
|
|
@@ -4,30 +4,33 @@ import * as fs from 'node:fs';
|
|
|
4
4
|
async function createTSConfigAliasPlugin({
|
|
5
5
|
root = process.cwd()
|
|
6
6
|
} = {}) {
|
|
7
|
-
const [{
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
const [{ default: alias }, tsconfig] = await Promise.all([
|
|
8
|
+
import('@rollup/plugin-alias'),
|
|
9
|
+
getTSConfig(root)
|
|
10
|
+
]);
|
|
10
11
|
const tsconfigPaths = tsconfig?.compilerOptions?.paths;
|
|
11
|
-
if (tsconfigPaths == null)
|
|
12
|
+
if (tsconfigPaths == null)
|
|
13
|
+
return void 0;
|
|
12
14
|
return alias({
|
|
13
15
|
entries: Object.entries(tsconfigPaths).map(([name, aliases]) => {
|
|
14
16
|
return {
|
|
15
|
-
find: name.includes(
|
|
16
|
-
replacement: aliases[0].replace(
|
|
17
|
+
find: name.includes("*") ? new RegExp(`^${name.replace(/\*/, "(.*)")}$`) : name,
|
|
18
|
+
replacement: aliases[0].replace("*", "$1")
|
|
17
19
|
};
|
|
18
20
|
})
|
|
19
21
|
});
|
|
20
22
|
}
|
|
21
23
|
async function getTSConfig(root) {
|
|
22
|
-
const tsconfigPath = path.join(root,
|
|
24
|
+
const tsconfigPath = path.join(root, "tsconfig.json");
|
|
23
25
|
if (!fs.existsSync(tsconfigPath)) {
|
|
24
|
-
return
|
|
26
|
+
return void 0;
|
|
25
27
|
}
|
|
26
28
|
try {
|
|
27
|
-
const tsconfig = JSON.parse(
|
|
29
|
+
const tsconfig = JSON.parse(
|
|
30
|
+
await fs.promises.readFile(tsconfigPath, "utf8")
|
|
31
|
+
);
|
|
28
32
|
return tsconfig;
|
|
29
33
|
} catch {
|
|
30
|
-
// intentional noop
|
|
31
34
|
}
|
|
32
35
|
}
|
|
33
36
|
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { posix } from 'node:path';
|
|
2
|
+
import { URLSearchParams } from 'node:url';
|
|
3
|
+
import { rollup } from 'rollup';
|
|
4
|
+
import { multiline } from '../shared/strings.mjs';
|
|
5
|
+
|
|
6
|
+
const PREFIX = "\0quilt-worker:";
|
|
7
|
+
const ENTRY_PREFIX = "\0quilt-worker-entry:";
|
|
8
|
+
const MAGIC_MODULE_WORKER = "quilt:module/worker.js";
|
|
9
|
+
function workers({
|
|
10
|
+
write = false,
|
|
11
|
+
baseURL,
|
|
12
|
+
contentForWorker = defaultContentForWorker,
|
|
13
|
+
plugins = defaultPlugins,
|
|
14
|
+
inputOptions = {},
|
|
15
|
+
outputOptions = {},
|
|
16
|
+
onIncludeFile
|
|
17
|
+
} = {}) {
|
|
18
|
+
let parentInputOptions;
|
|
19
|
+
const workerMap = /* @__PURE__ */ new Map();
|
|
20
|
+
return {
|
|
21
|
+
name: "@quilted/workers",
|
|
22
|
+
buildStart(inputOptions2) {
|
|
23
|
+
parentInputOptions = inputOptions2;
|
|
24
|
+
},
|
|
25
|
+
async resolveId(source, importer) {
|
|
26
|
+
if (!source.startsWith(PREFIX))
|
|
27
|
+
return null;
|
|
28
|
+
const { workerId, wrapper } = getWorkerRequest(source.replace(PREFIX, ""));
|
|
29
|
+
const resolvedWorker = await this.resolve(workerId, importer, {
|
|
30
|
+
skipSelf: true
|
|
31
|
+
});
|
|
32
|
+
if (resolvedWorker == null)
|
|
33
|
+
return null;
|
|
34
|
+
return `${PREFIX}${resolvedWorker.id}${wrapperToSearchString(wrapper)}`;
|
|
35
|
+
},
|
|
36
|
+
async load(id) {
|
|
37
|
+
if (!id.startsWith(PREFIX))
|
|
38
|
+
return null;
|
|
39
|
+
const { workerId, wrapper } = getWorkerRequest(id.replace(PREFIX, ""));
|
|
40
|
+
const workerContext = { module: workerId, wrapper };
|
|
41
|
+
const workerPlugins = [
|
|
42
|
+
{
|
|
43
|
+
name: "@quilted/workers/magic-modules",
|
|
44
|
+
resolveId(source) {
|
|
45
|
+
if (source.startsWith(ENTRY_PREFIX)) {
|
|
46
|
+
return { id: source };
|
|
47
|
+
}
|
|
48
|
+
if (source === MAGIC_MODULE_WORKER) {
|
|
49
|
+
return { id: workerId };
|
|
50
|
+
}
|
|
51
|
+
return null;
|
|
52
|
+
},
|
|
53
|
+
async load(id2) {
|
|
54
|
+
if (!id2.startsWith(ENTRY_PREFIX))
|
|
55
|
+
return null;
|
|
56
|
+
const { wrapper: wrapper2, workerId: workerId2 } = getWorkerRequest(
|
|
57
|
+
id2.replace(ENTRY_PREFIX, "")
|
|
58
|
+
);
|
|
59
|
+
const context = { module: workerId2, wrapper: wrapper2 };
|
|
60
|
+
const content = typeof contentForWorker === "function" ? await contentForWorker(context) : contentForWorker;
|
|
61
|
+
return content ?? defaultContentForWorker(context);
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
...typeof plugins === "function" ? await plugins(
|
|
65
|
+
[
|
|
66
|
+
...parentInputOptions.plugins?.filter(
|
|
67
|
+
(plugin) => Boolean(plugin)
|
|
68
|
+
) ?? []
|
|
69
|
+
],
|
|
70
|
+
workerContext
|
|
71
|
+
) : plugins
|
|
72
|
+
];
|
|
73
|
+
const workerInput = `${ENTRY_PREFIX}${workerId}${wrapperToSearchString(
|
|
74
|
+
wrapper
|
|
75
|
+
)}`;
|
|
76
|
+
const baseInputOptions = {
|
|
77
|
+
...parentInputOptions,
|
|
78
|
+
input: workerInput,
|
|
79
|
+
plugins: workerPlugins
|
|
80
|
+
};
|
|
81
|
+
const workerInputOptions = typeof inputOptions === "function" ? await inputOptions(baseInputOptions, workerContext) : baseInputOptions;
|
|
82
|
+
const baseOutputOptions = {
|
|
83
|
+
format: "iife",
|
|
84
|
+
inlineDynamicImports: true
|
|
85
|
+
};
|
|
86
|
+
const workerOutputOptions = typeof outputOptions === "function" ? await outputOptions(baseOutputOptions, workerContext) : { ...baseOutputOptions, ...outputOptions };
|
|
87
|
+
const shouldWrite = typeof write === "function" ? await write(workerContext) : write;
|
|
88
|
+
const bundle = await rollup(workerInputOptions);
|
|
89
|
+
const result = await (shouldWrite ? bundle.write(workerOutputOptions) : bundle.generate(workerOutputOptions));
|
|
90
|
+
const firstChunk = result.output.find(
|
|
91
|
+
(output) => output.type === "chunk"
|
|
92
|
+
);
|
|
93
|
+
if (firstChunk == null) {
|
|
94
|
+
workerMap.delete(workerId);
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
workerMap.set(workerId, firstChunk);
|
|
98
|
+
for (const module of Object.keys(firstChunk.modules)) {
|
|
99
|
+
onIncludeFile?.(module, id);
|
|
100
|
+
this.addWatchFile(module);
|
|
101
|
+
}
|
|
102
|
+
const filename = firstChunk.fileName;
|
|
103
|
+
let resolvedBaseURL = filename;
|
|
104
|
+
if (typeof baseURL === "string") {
|
|
105
|
+
resolvedBaseURL = posix.join(baseURL, filename);
|
|
106
|
+
} else if (typeof baseURL === "function") {
|
|
107
|
+
const returnedBaseURL = await baseURL({
|
|
108
|
+
...workerContext,
|
|
109
|
+
filename,
|
|
110
|
+
chunk: firstChunk,
|
|
111
|
+
outputOptions: workerOutputOptions
|
|
112
|
+
});
|
|
113
|
+
if (returnedBaseURL) {
|
|
114
|
+
resolvedBaseURL = posix.join(returnedBaseURL, filename);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return `export default ${JSON.stringify(resolvedBaseURL)};`;
|
|
118
|
+
},
|
|
119
|
+
generateBundle(_, bundle) {
|
|
120
|
+
if (write)
|
|
121
|
+
return;
|
|
122
|
+
for (const chunk of workerMap.values()) {
|
|
123
|
+
if (chunk.fileName in bundle)
|
|
124
|
+
continue;
|
|
125
|
+
bundle[chunk.fileName] = chunk;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
function getWorkerRequest(id) {
|
|
131
|
+
const [workerId, searchString] = id.split("?");
|
|
132
|
+
const searchParams = new URLSearchParams(searchString);
|
|
133
|
+
const wrapperModule = searchParams.get("module");
|
|
134
|
+
const wrapperFunction = searchParams.get("function");
|
|
135
|
+
return {
|
|
136
|
+
workerId,
|
|
137
|
+
wrapper: { module: wrapperModule, function: wrapperFunction }
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
const workerFunctionContent = (pkg) => /* @__PURE__ */ new Map([
|
|
141
|
+
["createWorker", `import ${JSON.stringify(MAGIC_MODULE_WORKER)};`],
|
|
142
|
+
[
|
|
143
|
+
"createThreadWorker",
|
|
144
|
+
multiline`
|
|
145
|
+
import {createThreadFromWebWorker} from ${JSON.stringify(pkg)};
|
|
146
|
+
import * as expose from ${JSON.stringify(MAGIC_MODULE_WORKER)};
|
|
147
|
+
|
|
148
|
+
createThreadFromWebWorker(self, {expose});
|
|
149
|
+
`
|
|
150
|
+
]
|
|
151
|
+
]);
|
|
152
|
+
const KNOWN_WRAPPER_MODULES = /* @__PURE__ */ new Map([
|
|
153
|
+
["@quilted/workers", workerFunctionContent("@quilted/workers")],
|
|
154
|
+
["@quilted/react-workers", workerFunctionContent("@quilted/react-workers")],
|
|
155
|
+
["@quilted/quilt/threads", workerFunctionContent("@quilted/quilt/threads")]
|
|
156
|
+
]);
|
|
157
|
+
function defaultContentForWorker({ wrapper }) {
|
|
158
|
+
const content = KNOWN_WRAPPER_MODULES.get(wrapper.module)?.get(
|
|
159
|
+
wrapper.function
|
|
160
|
+
);
|
|
161
|
+
if (content == null) {
|
|
162
|
+
throw new Error(`Unknown worker wrapper: ${JSON.stringify(wrapper)}`);
|
|
163
|
+
}
|
|
164
|
+
return content;
|
|
165
|
+
}
|
|
166
|
+
function defaultPlugins(mainBuildPlugins) {
|
|
167
|
+
return mainBuildPlugins.filter((plugin) => plugin.name !== "serve");
|
|
168
|
+
}
|
|
169
|
+
function wrapperToSearchString(wrapper) {
|
|
170
|
+
return `?${new URLSearchParams(Object.entries(wrapper)).toString()}`;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
export { workers };
|
package/build/esm/index.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
export { quiltAppBrowser, quiltAppServer } from './app.mjs';
|
|
1
|
+
export { quiltApp, quiltAppBrowser, quiltAppServer } from './app.mjs';
|
|
2
2
|
export { quiltModule } from './module.mjs';
|
|
3
|
-
export { quiltPackageESModules, quiltPackageESNext } from './package.mjs';
|
|
3
|
+
export { quiltPackage, quiltPackageESModules, quiltPackageESNext } from './package.mjs';
|
|
4
|
+
export { quiltServer } from './server.mjs';
|
package/build/esm/module.mjs
CHANGED
|
@@ -1,99 +1,106 @@
|
|
|
1
1
|
import * as path from 'node:path';
|
|
2
2
|
import { glob } from 'glob';
|
|
3
|
-
import {
|
|
3
|
+
import { resolveRoot } from './shared/path.mjs';
|
|
4
4
|
import { getNodePlugins, removeBuildFiles } from './shared/rollup.mjs';
|
|
5
5
|
import { loadPackageJSON } from './shared/package-json.mjs';
|
|
6
|
-
import {
|
|
6
|
+
import { getBrowserGroupTargetDetails, rollupGenerateOptionsForBrowsers } from './shared/browserslist.mjs';
|
|
7
|
+
import { resolveEnvOption } from './features/env.mjs';
|
|
7
8
|
|
|
8
9
|
async function quiltModule({
|
|
9
10
|
root: rootPath = process.cwd(),
|
|
11
|
+
entry,
|
|
10
12
|
env,
|
|
11
13
|
assets,
|
|
12
14
|
graphql = true
|
|
13
15
|
} = {}) {
|
|
14
|
-
const root =
|
|
15
|
-
const mode = (typeof env ===
|
|
16
|
-
const outputDirectory = path.join(root,
|
|
16
|
+
const root = resolveRoot(rootPath);
|
|
17
|
+
const mode = (typeof env === "object" ? env?.mode : env) ?? "production";
|
|
18
|
+
const outputDirectory = path.join(root, "build/assets");
|
|
17
19
|
const minify = assets?.minify ?? true;
|
|
18
|
-
const hash = assets?.hash ??
|
|
19
|
-
const
|
|
20
|
+
const hash = assets?.hash ?? "async-only";
|
|
21
|
+
const bundle = assets?.bundle ?? true;
|
|
22
|
+
const browserGroup = await getBrowserGroupTargetDetails(assets?.targets, {
|
|
20
23
|
root
|
|
21
24
|
});
|
|
22
|
-
const targetFilenamePart =
|
|
23
|
-
const [
|
|
24
|
-
visualizer
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
25
|
+
const targetFilenamePart = browserGroup.name ? `.${browserGroup.name}` : "";
|
|
26
|
+
const [
|
|
27
|
+
{ visualizer },
|
|
28
|
+
{ magicModuleEnv, replaceProcessEnv },
|
|
29
|
+
{ sourceCode },
|
|
30
|
+
{ esnext },
|
|
31
|
+
nodePlugins,
|
|
32
|
+
packageJSON
|
|
33
|
+
] = await Promise.all([
|
|
34
|
+
import('rollup-plugin-visualizer'),
|
|
35
|
+
import('./features/env.mjs'),
|
|
36
|
+
import('./features/source-code.mjs'),
|
|
37
|
+
import('./features/esnext.mjs'),
|
|
38
|
+
getNodePlugins({ bundle }),
|
|
39
|
+
loadPackageJSON(root)
|
|
40
|
+
]);
|
|
41
|
+
const finalEntry = entry ? path.resolve(root, entry) : await sourceForModule(root, packageJSON);
|
|
42
|
+
const plugins = [
|
|
43
|
+
...nodePlugins,
|
|
44
|
+
replaceProcessEnv({ mode }),
|
|
45
|
+
magicModuleEnv({ ...resolveEnvOption(env), mode }),
|
|
46
|
+
sourceCode({ mode, targets: browserGroup.browsers }),
|
|
47
|
+
esnext({ mode, targets: browserGroup.browsers }),
|
|
48
|
+
removeBuildFiles(["build/assets", "build/reports"], { root })
|
|
49
|
+
];
|
|
43
50
|
if (graphql) {
|
|
44
|
-
const {
|
|
45
|
-
|
|
46
|
-
} = await import('./features/graphql.mjs');
|
|
47
|
-
plugins.push(graphql({
|
|
48
|
-
manifest: false
|
|
49
|
-
}));
|
|
51
|
+
const { graphql: graphql2 } = await import('./features/graphql.mjs');
|
|
52
|
+
plugins.push(graphql2({ manifest: false }));
|
|
50
53
|
}
|
|
51
54
|
if (minify) {
|
|
52
|
-
const {
|
|
53
|
-
|
|
54
|
-
} = await import('rollup-plugin-esbuild');
|
|
55
|
-
plugins.push(minify());
|
|
55
|
+
const { minify: minify2 } = await import('rollup-plugin-esbuild');
|
|
56
|
+
plugins.push(minify2());
|
|
56
57
|
}
|
|
57
|
-
plugins.push(
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
58
|
+
plugins.push(
|
|
59
|
+
visualizer({
|
|
60
|
+
template: "treemap",
|
|
61
|
+
open: false,
|
|
62
|
+
brotliSize: true,
|
|
63
|
+
filename: path.resolve(
|
|
64
|
+
root,
|
|
65
|
+
`build/reports/bundle-visualizer${targetFilenamePart}.html`
|
|
66
|
+
)
|
|
67
|
+
})
|
|
68
|
+
);
|
|
63
69
|
return {
|
|
64
|
-
input:
|
|
70
|
+
input: finalEntry,
|
|
65
71
|
plugins,
|
|
66
72
|
onwarn(warning, defaultWarn) {
|
|
67
|
-
|
|
68
|
-
// include 'use client' directives.
|
|
69
|
-
if (warning.code === 'MODULE_LEVEL_DIRECTIVE' && /['"]use client['"]/.test(warning.message)) {
|
|
73
|
+
if (warning.code === "MODULE_LEVEL_DIRECTIVE" && /['"]use client['"]/.test(warning.message)) {
|
|
70
74
|
return;
|
|
71
75
|
}
|
|
72
76
|
defaultWarn(warning);
|
|
73
77
|
},
|
|
74
78
|
output: {
|
|
75
|
-
format:
|
|
79
|
+
format: "esm",
|
|
76
80
|
dir: outputDirectory,
|
|
77
|
-
entryFileNames: `[name]${targetFilenamePart}${hash === true ? `.[hash]` :
|
|
78
|
-
chunkFileNames: `[name]${targetFilenamePart}${hash === true || hash ===
|
|
79
|
-
assetFileNames: `[name]${targetFilenamePart}${hash === true ? `.[hash]` :
|
|
81
|
+
entryFileNames: `[name]${targetFilenamePart}${hash === true ? `.[hash]` : ""}.js`,
|
|
82
|
+
chunkFileNames: `[name]${targetFilenamePart}${hash === true || hash === "async-only" ? `.[hash]` : ""}.js`,
|
|
83
|
+
assetFileNames: `[name]${targetFilenamePart}${hash === true ? `.[hash]` : ""}.[ext]`,
|
|
84
|
+
generatedCode: await rollupGenerateOptionsForBrowsers(
|
|
85
|
+
browserGroup.browsers
|
|
86
|
+
)
|
|
80
87
|
}
|
|
81
88
|
};
|
|
82
89
|
}
|
|
83
90
|
async function sourceForModule(root, packageJSON) {
|
|
84
|
-
const {
|
|
85
|
-
|
|
86
|
-
exports
|
|
87
|
-
} = packageJSON;
|
|
88
|
-
const entryFromPackageJSON = main ?? exports?.['.'];
|
|
91
|
+
const { main, exports } = packageJSON;
|
|
92
|
+
const entryFromPackageJSON = main ?? exports?.["."];
|
|
89
93
|
if (entryFromPackageJSON) {
|
|
90
94
|
return path.resolve(root, entryFromPackageJSON);
|
|
91
95
|
}
|
|
92
|
-
const possibleSourceFiles = await glob(
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
96
|
+
const possibleSourceFiles = await glob(
|
|
97
|
+
"{index,module,entry,input}.{ts,tsx,mjs,js,jsx}",
|
|
98
|
+
{
|
|
99
|
+
cwd: root,
|
|
100
|
+
nodir: true,
|
|
101
|
+
absolute: true
|
|
102
|
+
}
|
|
103
|
+
);
|
|
97
104
|
return possibleSourceFiles[0];
|
|
98
105
|
}
|
|
99
106
|
|