@quilted/rollup 0.1.10 → 0.1.11
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 +8 -0
- package/build/cjs/app.cjs +13 -9
- package/build/cjs/index.cjs +2 -0
- package/build/cjs/package.cjs +112 -0
- package/build/cjs/shared/package-json.cjs +31 -0
- package/build/esm/app.mjs +13 -9
- package/build/esm/index.mjs +1 -0
- package/build/esm/package.mjs +91 -0
- package/build/esm/shared/package-json.mjs +10 -0
- package/build/esnext/app.esnext +13 -9
- package/build/esnext/index.esnext +1 -0
- package/build/esnext/package.esnext +91 -0
- package/build/esnext/shared/package-json.esnext +10 -0
- package/build/tsconfig.tsbuildinfo +1 -1
- package/build/typescript/app.d.ts +5 -1
- package/build/typescript/app.d.ts.map +1 -1
- package/build/typescript/index.d.ts +1 -0
- package/build/typescript/index.d.ts.map +1 -1
- package/build/typescript/package.d.ts +21 -0
- package/build/typescript/package.d.ts.map +1 -0
- package/build/typescript/shared/package-json.d.ts +6 -0
- package/build/typescript/shared/package-json.d.ts.map +1 -0
- package/package.json +1 -1
- package/source/app.ts +29 -9
- package/source/index.ts +1 -0
- package/source/package.ts +143 -0
- package/source/shared/package-json.ts +17 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# @quilted/rollup
|
|
2
2
|
|
|
3
|
+
## 0.1.11
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`a1ecacac`](https://github.com/lemonmade/quilt/commit/a1ecacaca6229233cdecb7d27cb6165974aefcc6) Thanks [@lemonmade](https://github.com/lemonmade)! - Add package rollup config
|
|
8
|
+
|
|
9
|
+
- [`06b9abe3`](https://github.com/lemonmade/quilt/commit/06b9abe3a399e04b9fb9e8abe82b5f4d87e005dd) Thanks [@lemonmade](https://github.com/lemonmade)! - Fix some output file names
|
|
10
|
+
|
|
3
11
|
## 0.1.10
|
|
4
12
|
|
|
5
13
|
### Patch Changes
|
package/build/cjs/app.cjs
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
var path = require('node:path');
|
|
4
4
|
var fs = require('node:fs/promises');
|
|
5
5
|
var glob = require('glob');
|
|
6
|
+
var node_url = require('node:url');
|
|
6
7
|
var constants = require('./constants.cjs');
|
|
7
8
|
var strings = require('./shared/strings.cjs');
|
|
8
9
|
var rollup = require('./shared/rollup.cjs');
|
|
@@ -29,6 +30,7 @@ var path__namespace = /*#__PURE__*/_interopNamespaceDefault(path);
|
|
|
29
30
|
var fs__namespace = /*#__PURE__*/_interopNamespaceDefault(fs);
|
|
30
31
|
|
|
31
32
|
async function quiltAppBrowser({
|
|
33
|
+
root: rootPath = process.cwd(),
|
|
32
34
|
app,
|
|
33
35
|
entry,
|
|
34
36
|
env,
|
|
@@ -36,7 +38,7 @@ async function quiltAppBrowser({
|
|
|
36
38
|
module,
|
|
37
39
|
graphql = true
|
|
38
40
|
} = {}) {
|
|
39
|
-
const root =
|
|
41
|
+
const root = node_url.fileURLToPath(rootPath);
|
|
40
42
|
const mode = (typeof env === 'object' ? env?.mode : undefined) ?? 'production';
|
|
41
43
|
const minify = assets?.minify ?? mode === 'production';
|
|
42
44
|
const baseURL = assets?.baseURL ?? '/assets/';
|
|
@@ -53,6 +55,8 @@ async function quiltAppBrowser({
|
|
|
53
55
|
const targetName = targets.name ?? 'defaults';
|
|
54
56
|
return config[targetName] ?? ['defaults'];
|
|
55
57
|
})());
|
|
58
|
+
const normalizedTargetName = targets.name === 'defaults' ? 'default' : targets.name;
|
|
59
|
+
const targetFilenamePart = normalizedTargetName ? `.${normalizedTargetName}` : '';
|
|
56
60
|
const [{
|
|
57
61
|
visualizer
|
|
58
62
|
}, {
|
|
@@ -124,7 +128,7 @@ async function quiltAppBrowser({
|
|
|
124
128
|
graphql
|
|
125
129
|
} = await Promise.resolve().then(function () { return require('./features/graphql.cjs'); });
|
|
126
130
|
plugins.push(graphql({
|
|
127
|
-
manifest: path__namespace.resolve(`manifests/graphql.json`)
|
|
131
|
+
manifest: path__namespace.resolve(`manifests/graphql${targetFilenamePart}.json`)
|
|
128
132
|
}));
|
|
129
133
|
}
|
|
130
134
|
if (minify) {
|
|
@@ -143,13 +147,13 @@ async function quiltAppBrowser({
|
|
|
143
147
|
id,
|
|
144
148
|
cacheKey,
|
|
145
149
|
baseUrl: baseURL,
|
|
146
|
-
path: path__namespace.resolve(`build/manifests/assets.json`),
|
|
150
|
+
path: path__namespace.resolve(`build/manifests/assets${targetFilenamePart}.json`),
|
|
147
151
|
priority: assets?.priority
|
|
148
152
|
}), visualizer({
|
|
149
153
|
template: 'treemap',
|
|
150
154
|
open: false,
|
|
151
155
|
brotliSize: true,
|
|
152
|
-
filename: path__namespace.resolve(`build/reports/bundle-visualizer.html`)
|
|
156
|
+
filename: path__namespace.resolve(`build/reports/bundle-visualizer${targetFilenamePart}.html`)
|
|
153
157
|
}));
|
|
154
158
|
const finalEntry = entry ?? (await glob.glob('{browser,client}.{ts,tsx,mjs,js,jsx}', {
|
|
155
159
|
cwd: root,
|
|
@@ -171,9 +175,9 @@ async function quiltAppBrowser({
|
|
|
171
175
|
// format: isESM ? 'esm' : 'systemjs',
|
|
172
176
|
format: 'esm',
|
|
173
177
|
dir: path__namespace.resolve(`build/assets`),
|
|
174
|
-
entryFileNames: `app.[hash].js`,
|
|
175
|
-
assetFileNames: `[name].[hash].[ext]`,
|
|
176
|
-
chunkFileNames: `[name].[hash].js`,
|
|
178
|
+
entryFileNames: `app${targetFilenamePart}.[hash].js`,
|
|
179
|
+
assetFileNames: `[name]${targetFilenamePart}.[hash].[ext]`,
|
|
180
|
+
chunkFileNames: `[name]${targetFilenamePart}.[hash].js`,
|
|
177
181
|
manualChunks: createManualChunksSorter()
|
|
178
182
|
}
|
|
179
183
|
};
|
|
@@ -269,8 +273,8 @@ async function quiltAppServer({
|
|
|
269
273
|
plugins.push(visualizer({
|
|
270
274
|
template: 'treemap',
|
|
271
275
|
open: false,
|
|
272
|
-
brotliSize:
|
|
273
|
-
filename: path__namespace.resolve(`build/reports/bundle-visualizer.html`)
|
|
276
|
+
brotliSize: false,
|
|
277
|
+
filename: path__namespace.resolve(`build/reports/bundle-visualizer.server.html`)
|
|
274
278
|
}));
|
|
275
279
|
const finalEntry = entry ?? (await glob.glob('{server,service,backend}.{ts,tsx,mjs,js,jsx}', {
|
|
276
280
|
cwd: root,
|
package/build/cjs/index.cjs
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var app = require('./app.cjs');
|
|
4
|
+
var _package = require('./package.cjs');
|
|
4
5
|
|
|
5
6
|
|
|
6
7
|
|
|
7
8
|
exports.quiltAppBrowser = app.quiltAppBrowser;
|
|
8
9
|
exports.quiltAppServer = app.quiltAppServer;
|
|
10
|
+
exports.quiltPackageESModules = _package.quiltPackageESModules;
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var path = require('node:path');
|
|
4
|
+
var glob = require('glob');
|
|
5
|
+
var node_url = require('node:url');
|
|
6
|
+
var rollup = require('./shared/rollup.cjs');
|
|
7
|
+
var packageJson = require('./shared/package-json.cjs');
|
|
8
|
+
|
|
9
|
+
function _interopNamespaceDefault(e) {
|
|
10
|
+
var n = Object.create(null);
|
|
11
|
+
if (e) {
|
|
12
|
+
Object.keys(e).forEach(function (k) {
|
|
13
|
+
if (k !== 'default') {
|
|
14
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
15
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
16
|
+
enumerable: true,
|
|
17
|
+
get: function () { return e[k]; }
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
n["default"] = e;
|
|
23
|
+
return Object.freeze(n);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
var path__namespace = /*#__PURE__*/_interopNamespaceDefault(path);
|
|
27
|
+
|
|
28
|
+
async function quiltPackageESModules({
|
|
29
|
+
root: rootPath = process.cwd()
|
|
30
|
+
} = {}) {
|
|
31
|
+
const root = node_url.fileURLToPath(rootPath);
|
|
32
|
+
const outputDirectory = path__namespace.join(root, 'build/esm');
|
|
33
|
+
const [{
|
|
34
|
+
sourceCode
|
|
35
|
+
}, nodePlugins, packageJSON] = await Promise.all([Promise.resolve().then(function () { return require('./features/source-code.cjs'); }), rollup.getNodePlugins(), packageJson.loadPackageJSON(root)]);
|
|
36
|
+
const [entries] = await Promise.all([sourceEntriesForPackage(root, packageJSON)]);
|
|
37
|
+
let sourceRoot = root;
|
|
38
|
+
for (const entry of Object.values(entries)) {
|
|
39
|
+
if (!entry.startsWith(root)) continue;
|
|
40
|
+
sourceRoot = path__namespace.resolve(root, path__namespace.relative(root, entry).split(path__namespace.sep)[0] ?? '.');
|
|
41
|
+
break;
|
|
42
|
+
}
|
|
43
|
+
const plugins = [...nodePlugins, sourceCode({
|
|
44
|
+
mode: 'production'
|
|
45
|
+
}), rollup.removeBuildFiles(['build/esm'], {
|
|
46
|
+
root
|
|
47
|
+
})];
|
|
48
|
+
return {
|
|
49
|
+
input: entries,
|
|
50
|
+
plugins,
|
|
51
|
+
onwarn(warning, defaultWarn) {
|
|
52
|
+
// Removes annoying warnings for React-focused libraries that
|
|
53
|
+
// include 'use client' directives.
|
|
54
|
+
if (warning.code === 'MODULE_LEVEL_DIRECTIVE' && /['"]use client['"]/.test(warning.message)) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
defaultWarn(warning);
|
|
58
|
+
},
|
|
59
|
+
output: {
|
|
60
|
+
preserveModules: true,
|
|
61
|
+
preserveModulesRoot: sourceRoot,
|
|
62
|
+
format: 'esm',
|
|
63
|
+
dir: outputDirectory,
|
|
64
|
+
entryFileNames: `[name].mjs`,
|
|
65
|
+
assetFileNames: `[name].[ext]`
|
|
66
|
+
// chunkFileNames: createChunkNamer({
|
|
67
|
+
// extension: ESM_EXTENSION,
|
|
68
|
+
// sourceRoot: sourceRootDirectory,
|
|
69
|
+
// }),
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
async function sourceEntriesForPackage(root, packageJSON) {
|
|
75
|
+
const {
|
|
76
|
+
main,
|
|
77
|
+
exports
|
|
78
|
+
} = packageJSON;
|
|
79
|
+
const entries = {};
|
|
80
|
+
if (typeof main === 'string') {
|
|
81
|
+
entries['.'] = await resolveTargetFileAsSource(main, root);
|
|
82
|
+
}
|
|
83
|
+
if (typeof exports === 'string') {
|
|
84
|
+
entries['.'] = await resolveTargetFileAsSource(exports, root);
|
|
85
|
+
return entries;
|
|
86
|
+
} else if (exports == null || typeof exports !== 'object') {
|
|
87
|
+
return entries;
|
|
88
|
+
}
|
|
89
|
+
for (const [exportPath, exportCondition] of Object.entries(exports)) {
|
|
90
|
+
let targetFile = null;
|
|
91
|
+
if (exportCondition == null) continue;
|
|
92
|
+
if (typeof exportCondition === 'string') {
|
|
93
|
+
targetFile = exportCondition;
|
|
94
|
+
} else {
|
|
95
|
+
targetFile ?? (targetFile = exportCondition['source'] ?? exportCondition['quilt:source'] ?? exportCondition['quilt:esnext'] ?? Object.values(exportCondition).find(condition => typeof condition === 'string' && condition.startsWith('./build/')));
|
|
96
|
+
}
|
|
97
|
+
if (targetFile == null) continue;
|
|
98
|
+
const sourceFile = await resolveTargetFileAsSource(targetFile, root);
|
|
99
|
+
entries[exportPath] = sourceFile;
|
|
100
|
+
}
|
|
101
|
+
return entries;
|
|
102
|
+
}
|
|
103
|
+
async function resolveTargetFileAsSource(file, root) {
|
|
104
|
+
const sourceFile = file.includes('/build/') ? (await glob.glob(file.replace(/[/]build[/][^/]+[/]/, '/*/').replace(/(\.d\.ts|\.[\w]+)$/, '.*'), {
|
|
105
|
+
cwd: root,
|
|
106
|
+
absolute: true,
|
|
107
|
+
ignore: [path__namespace.resolve(root, file)]
|
|
108
|
+
}))[0] : path__namespace.resolve(root, file);
|
|
109
|
+
return sourceFile;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
exports.quiltPackageESModules = quiltPackageESModules;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var path = require('node:path');
|
|
4
|
+
var node_url = require('node:url');
|
|
5
|
+
var fs = require('node:fs/promises');
|
|
6
|
+
|
|
7
|
+
function _interopNamespaceDefault(e) {
|
|
8
|
+
var n = Object.create(null);
|
|
9
|
+
if (e) {
|
|
10
|
+
Object.keys(e).forEach(function (k) {
|
|
11
|
+
if (k !== 'default') {
|
|
12
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
13
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
get: function () { return e[k]; }
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
n["default"] = e;
|
|
21
|
+
return Object.freeze(n);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
var path__namespace = /*#__PURE__*/_interopNamespaceDefault(path);
|
|
25
|
+
|
|
26
|
+
async function loadPackageJSON(root) {
|
|
27
|
+
const file = await fs.readFile(path__namespace.join(node_url.fileURLToPath(root), 'package.json'), 'utf8');
|
|
28
|
+
return JSON.parse(file);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
exports.loadPackageJSON = loadPackageJSON;
|
package/build/esm/app.mjs
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import * as path from 'node:path';
|
|
2
2
|
import * as fs from 'node:fs/promises';
|
|
3
3
|
import { glob } from 'glob';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
4
5
|
import { MAGIC_MODULE_ENTRY, MAGIC_MODULE_APP_COMPONENT, MAGIC_MODULE_REQUEST_ROUTER, MAGIC_MODULE_BROWSER_ASSETS } from './constants.mjs';
|
|
5
6
|
import { multiline } from './shared/strings.mjs';
|
|
6
7
|
import { getNodePlugins, removeBuildFiles } from './shared/rollup.mjs';
|
|
7
8
|
import { createMagicModulePlugin } from './shared/magic-module.mjs';
|
|
8
9
|
|
|
9
10
|
async function quiltAppBrowser({
|
|
11
|
+
root: rootPath = process.cwd(),
|
|
10
12
|
app,
|
|
11
13
|
entry,
|
|
12
14
|
env,
|
|
@@ -14,7 +16,7 @@ async function quiltAppBrowser({
|
|
|
14
16
|
module,
|
|
15
17
|
graphql = true
|
|
16
18
|
} = {}) {
|
|
17
|
-
const root =
|
|
19
|
+
const root = fileURLToPath(rootPath);
|
|
18
20
|
const mode = (typeof env === 'object' ? env?.mode : undefined) ?? 'production';
|
|
19
21
|
const minify = assets?.minify ?? mode === 'production';
|
|
20
22
|
const baseURL = assets?.baseURL ?? '/assets/';
|
|
@@ -31,6 +33,8 @@ async function quiltAppBrowser({
|
|
|
31
33
|
const targetName = targets.name ?? 'defaults';
|
|
32
34
|
return config[targetName] ?? ['defaults'];
|
|
33
35
|
})());
|
|
36
|
+
const normalizedTargetName = targets.name === 'defaults' ? 'default' : targets.name;
|
|
37
|
+
const targetFilenamePart = normalizedTargetName ? `.${normalizedTargetName}` : '';
|
|
34
38
|
const [{
|
|
35
39
|
visualizer
|
|
36
40
|
}, {
|
|
@@ -102,7 +106,7 @@ async function quiltAppBrowser({
|
|
|
102
106
|
graphql
|
|
103
107
|
} = await import('./features/graphql.mjs');
|
|
104
108
|
plugins.push(graphql({
|
|
105
|
-
manifest: path.resolve(`manifests/graphql.json`)
|
|
109
|
+
manifest: path.resolve(`manifests/graphql${targetFilenamePart}.json`)
|
|
106
110
|
}));
|
|
107
111
|
}
|
|
108
112
|
if (minify) {
|
|
@@ -121,13 +125,13 @@ async function quiltAppBrowser({
|
|
|
121
125
|
id,
|
|
122
126
|
cacheKey,
|
|
123
127
|
baseUrl: baseURL,
|
|
124
|
-
path: path.resolve(`build/manifests/assets.json`),
|
|
128
|
+
path: path.resolve(`build/manifests/assets${targetFilenamePart}.json`),
|
|
125
129
|
priority: assets?.priority
|
|
126
130
|
}), visualizer({
|
|
127
131
|
template: 'treemap',
|
|
128
132
|
open: false,
|
|
129
133
|
brotliSize: true,
|
|
130
|
-
filename: path.resolve(`build/reports/bundle-visualizer.html`)
|
|
134
|
+
filename: path.resolve(`build/reports/bundle-visualizer${targetFilenamePart}.html`)
|
|
131
135
|
}));
|
|
132
136
|
const finalEntry = entry ?? (await glob('{browser,client}.{ts,tsx,mjs,js,jsx}', {
|
|
133
137
|
cwd: root,
|
|
@@ -149,9 +153,9 @@ async function quiltAppBrowser({
|
|
|
149
153
|
// format: isESM ? 'esm' : 'systemjs',
|
|
150
154
|
format: 'esm',
|
|
151
155
|
dir: path.resolve(`build/assets`),
|
|
152
|
-
entryFileNames: `app.[hash].js`,
|
|
153
|
-
assetFileNames: `[name].[hash].[ext]`,
|
|
154
|
-
chunkFileNames: `[name].[hash].js`,
|
|
156
|
+
entryFileNames: `app${targetFilenamePart}.[hash].js`,
|
|
157
|
+
assetFileNames: `[name]${targetFilenamePart}.[hash].[ext]`,
|
|
158
|
+
chunkFileNames: `[name]${targetFilenamePart}.[hash].js`,
|
|
155
159
|
manualChunks: createManualChunksSorter()
|
|
156
160
|
}
|
|
157
161
|
};
|
|
@@ -247,8 +251,8 @@ async function quiltAppServer({
|
|
|
247
251
|
plugins.push(visualizer({
|
|
248
252
|
template: 'treemap',
|
|
249
253
|
open: false,
|
|
250
|
-
brotliSize:
|
|
251
|
-
filename: path.resolve(`build/reports/bundle-visualizer.html`)
|
|
254
|
+
brotliSize: false,
|
|
255
|
+
filename: path.resolve(`build/reports/bundle-visualizer.server.html`)
|
|
252
256
|
}));
|
|
253
257
|
const finalEntry = entry ?? (await glob('{server,service,backend}.{ts,tsx,mjs,js,jsx}', {
|
|
254
258
|
cwd: root,
|
package/build/esm/index.mjs
CHANGED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import * as path from 'node:path';
|
|
2
|
+
import { glob } from 'glob';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
import { getNodePlugins, removeBuildFiles } from './shared/rollup.mjs';
|
|
5
|
+
import { loadPackageJSON } from './shared/package-json.mjs';
|
|
6
|
+
|
|
7
|
+
async function quiltPackageESModules({
|
|
8
|
+
root: rootPath = process.cwd()
|
|
9
|
+
} = {}) {
|
|
10
|
+
const root = fileURLToPath(rootPath);
|
|
11
|
+
const outputDirectory = path.join(root, 'build/esm');
|
|
12
|
+
const [{
|
|
13
|
+
sourceCode
|
|
14
|
+
}, nodePlugins, packageJSON] = await Promise.all([import('./features/source-code.mjs'), getNodePlugins(), loadPackageJSON(root)]);
|
|
15
|
+
const [entries] = await Promise.all([sourceEntriesForPackage(root, packageJSON)]);
|
|
16
|
+
let sourceRoot = root;
|
|
17
|
+
for (const entry of Object.values(entries)) {
|
|
18
|
+
if (!entry.startsWith(root)) continue;
|
|
19
|
+
sourceRoot = path.resolve(root, path.relative(root, entry).split(path.sep)[0] ?? '.');
|
|
20
|
+
break;
|
|
21
|
+
}
|
|
22
|
+
const plugins = [...nodePlugins, sourceCode({
|
|
23
|
+
mode: 'production'
|
|
24
|
+
}), removeBuildFiles(['build/esm'], {
|
|
25
|
+
root
|
|
26
|
+
})];
|
|
27
|
+
return {
|
|
28
|
+
input: entries,
|
|
29
|
+
plugins,
|
|
30
|
+
onwarn(warning, defaultWarn) {
|
|
31
|
+
// Removes annoying warnings for React-focused libraries that
|
|
32
|
+
// include 'use client' directives.
|
|
33
|
+
if (warning.code === 'MODULE_LEVEL_DIRECTIVE' && /['"]use client['"]/.test(warning.message)) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
defaultWarn(warning);
|
|
37
|
+
},
|
|
38
|
+
output: {
|
|
39
|
+
preserveModules: true,
|
|
40
|
+
preserveModulesRoot: sourceRoot,
|
|
41
|
+
format: 'esm',
|
|
42
|
+
dir: outputDirectory,
|
|
43
|
+
entryFileNames: `[name].mjs`,
|
|
44
|
+
assetFileNames: `[name].[ext]`
|
|
45
|
+
// chunkFileNames: createChunkNamer({
|
|
46
|
+
// extension: ESM_EXTENSION,
|
|
47
|
+
// sourceRoot: sourceRootDirectory,
|
|
48
|
+
// }),
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
async function sourceEntriesForPackage(root, packageJSON) {
|
|
54
|
+
const {
|
|
55
|
+
main,
|
|
56
|
+
exports
|
|
57
|
+
} = packageJSON;
|
|
58
|
+
const entries = {};
|
|
59
|
+
if (typeof main === 'string') {
|
|
60
|
+
entries['.'] = await resolveTargetFileAsSource(main, root);
|
|
61
|
+
}
|
|
62
|
+
if (typeof exports === 'string') {
|
|
63
|
+
entries['.'] = await resolveTargetFileAsSource(exports, root);
|
|
64
|
+
return entries;
|
|
65
|
+
} else if (exports == null || typeof exports !== 'object') {
|
|
66
|
+
return entries;
|
|
67
|
+
}
|
|
68
|
+
for (const [exportPath, exportCondition] of Object.entries(exports)) {
|
|
69
|
+
let targetFile = null;
|
|
70
|
+
if (exportCondition == null) continue;
|
|
71
|
+
if (typeof exportCondition === 'string') {
|
|
72
|
+
targetFile = exportCondition;
|
|
73
|
+
} else {
|
|
74
|
+
targetFile ?? (targetFile = exportCondition['source'] ?? exportCondition['quilt:source'] ?? exportCondition['quilt:esnext'] ?? Object.values(exportCondition).find(condition => typeof condition === 'string' && condition.startsWith('./build/')));
|
|
75
|
+
}
|
|
76
|
+
if (targetFile == null) continue;
|
|
77
|
+
const sourceFile = await resolveTargetFileAsSource(targetFile, root);
|
|
78
|
+
entries[exportPath] = sourceFile;
|
|
79
|
+
}
|
|
80
|
+
return entries;
|
|
81
|
+
}
|
|
82
|
+
async function resolveTargetFileAsSource(file, root) {
|
|
83
|
+
const sourceFile = file.includes('/build/') ? (await glob(file.replace(/[/]build[/][^/]+[/]/, '/*/').replace(/(\.d\.ts|\.[\w]+)$/, '.*'), {
|
|
84
|
+
cwd: root,
|
|
85
|
+
absolute: true,
|
|
86
|
+
ignore: [path.resolve(root, file)]
|
|
87
|
+
}))[0] : path.resolve(root, file);
|
|
88
|
+
return sourceFile;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export { quiltPackageESModules };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as path from 'node:path';
|
|
2
|
+
import { fileURLToPath } from 'node:url';
|
|
3
|
+
import { readFile } from 'node:fs/promises';
|
|
4
|
+
|
|
5
|
+
async function loadPackageJSON(root) {
|
|
6
|
+
const file = await readFile(path.join(fileURLToPath(root), 'package.json'), 'utf8');
|
|
7
|
+
return JSON.parse(file);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export { loadPackageJSON };
|
package/build/esnext/app.esnext
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import * as path from 'node:path';
|
|
2
2
|
import * as fs from 'node:fs/promises';
|
|
3
3
|
import { glob } from 'glob';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
4
5
|
import { MAGIC_MODULE_ENTRY, MAGIC_MODULE_APP_COMPONENT, MAGIC_MODULE_REQUEST_ROUTER, MAGIC_MODULE_BROWSER_ASSETS } from './constants.esnext';
|
|
5
6
|
import { multiline } from './shared/strings.esnext';
|
|
6
7
|
import { getNodePlugins, removeBuildFiles } from './shared/rollup.esnext';
|
|
7
8
|
import { createMagicModulePlugin } from './shared/magic-module.esnext';
|
|
8
9
|
|
|
9
10
|
async function quiltAppBrowser({
|
|
11
|
+
root: rootPath = process.cwd(),
|
|
10
12
|
app,
|
|
11
13
|
entry,
|
|
12
14
|
env,
|
|
@@ -14,7 +16,7 @@ async function quiltAppBrowser({
|
|
|
14
16
|
module,
|
|
15
17
|
graphql = true
|
|
16
18
|
} = {}) {
|
|
17
|
-
const root =
|
|
19
|
+
const root = fileURLToPath(rootPath);
|
|
18
20
|
const mode = (typeof env === 'object' ? env?.mode : undefined) ?? 'production';
|
|
19
21
|
const minify = assets?.minify ?? mode === 'production';
|
|
20
22
|
const baseURL = assets?.baseURL ?? '/assets/';
|
|
@@ -31,6 +33,8 @@ async function quiltAppBrowser({
|
|
|
31
33
|
const targetName = targets.name ?? 'defaults';
|
|
32
34
|
return config[targetName] ?? ['defaults'];
|
|
33
35
|
})());
|
|
36
|
+
const normalizedTargetName = targets.name === 'defaults' ? 'default' : targets.name;
|
|
37
|
+
const targetFilenamePart = normalizedTargetName ? `.${normalizedTargetName}` : '';
|
|
34
38
|
const [{
|
|
35
39
|
visualizer
|
|
36
40
|
}, {
|
|
@@ -102,7 +106,7 @@ async function quiltAppBrowser({
|
|
|
102
106
|
graphql
|
|
103
107
|
} = await import('./features/graphql.esnext');
|
|
104
108
|
plugins.push(graphql({
|
|
105
|
-
manifest: path.resolve(`manifests/graphql.json`)
|
|
109
|
+
manifest: path.resolve(`manifests/graphql${targetFilenamePart}.json`)
|
|
106
110
|
}));
|
|
107
111
|
}
|
|
108
112
|
if (minify) {
|
|
@@ -121,13 +125,13 @@ async function quiltAppBrowser({
|
|
|
121
125
|
id,
|
|
122
126
|
cacheKey,
|
|
123
127
|
baseUrl: baseURL,
|
|
124
|
-
path: path.resolve(`build/manifests/assets.json`),
|
|
128
|
+
path: path.resolve(`build/manifests/assets${targetFilenamePart}.json`),
|
|
125
129
|
priority: assets?.priority
|
|
126
130
|
}), visualizer({
|
|
127
131
|
template: 'treemap',
|
|
128
132
|
open: false,
|
|
129
133
|
brotliSize: true,
|
|
130
|
-
filename: path.resolve(`build/reports/bundle-visualizer.html`)
|
|
134
|
+
filename: path.resolve(`build/reports/bundle-visualizer${targetFilenamePart}.html`)
|
|
131
135
|
}));
|
|
132
136
|
const finalEntry = entry ?? (await glob('{browser,client}.{ts,tsx,mjs,js,jsx}', {
|
|
133
137
|
cwd: root,
|
|
@@ -149,9 +153,9 @@ async function quiltAppBrowser({
|
|
|
149
153
|
// format: isESM ? 'esm' : 'systemjs',
|
|
150
154
|
format: 'esm',
|
|
151
155
|
dir: path.resolve(`build/assets`),
|
|
152
|
-
entryFileNames: `app.[hash].js`,
|
|
153
|
-
assetFileNames: `[name].[hash].[ext]`,
|
|
154
|
-
chunkFileNames: `[name].[hash].js`,
|
|
156
|
+
entryFileNames: `app${targetFilenamePart}.[hash].js`,
|
|
157
|
+
assetFileNames: `[name]${targetFilenamePart}.[hash].[ext]`,
|
|
158
|
+
chunkFileNames: `[name]${targetFilenamePart}.[hash].js`,
|
|
155
159
|
manualChunks: createManualChunksSorter()
|
|
156
160
|
}
|
|
157
161
|
};
|
|
@@ -247,8 +251,8 @@ async function quiltAppServer({
|
|
|
247
251
|
plugins.push(visualizer({
|
|
248
252
|
template: 'treemap',
|
|
249
253
|
open: false,
|
|
250
|
-
brotliSize:
|
|
251
|
-
filename: path.resolve(`build/reports/bundle-visualizer.html`)
|
|
254
|
+
brotliSize: false,
|
|
255
|
+
filename: path.resolve(`build/reports/bundle-visualizer.server.html`)
|
|
252
256
|
}));
|
|
253
257
|
const finalEntry = entry ?? (await glob('{server,service,backend}.{ts,tsx,mjs,js,jsx}', {
|
|
254
258
|
cwd: root,
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import * as path from 'node:path';
|
|
2
|
+
import { glob } from 'glob';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
import { getNodePlugins, removeBuildFiles } from './shared/rollup.esnext';
|
|
5
|
+
import { loadPackageJSON } from './shared/package-json.esnext';
|
|
6
|
+
|
|
7
|
+
async function quiltPackageESModules({
|
|
8
|
+
root: rootPath = process.cwd()
|
|
9
|
+
} = {}) {
|
|
10
|
+
const root = fileURLToPath(rootPath);
|
|
11
|
+
const outputDirectory = path.join(root, 'build/esm');
|
|
12
|
+
const [{
|
|
13
|
+
sourceCode
|
|
14
|
+
}, nodePlugins, packageJSON] = await Promise.all([import('./features/source-code.esnext'), getNodePlugins(), loadPackageJSON(root)]);
|
|
15
|
+
const [entries] = await Promise.all([sourceEntriesForPackage(root, packageJSON)]);
|
|
16
|
+
let sourceRoot = root;
|
|
17
|
+
for (const entry of Object.values(entries)) {
|
|
18
|
+
if (!entry.startsWith(root)) continue;
|
|
19
|
+
sourceRoot = path.resolve(root, path.relative(root, entry).split(path.sep)[0] ?? '.');
|
|
20
|
+
break;
|
|
21
|
+
}
|
|
22
|
+
const plugins = [...nodePlugins, sourceCode({
|
|
23
|
+
mode: 'production'
|
|
24
|
+
}), removeBuildFiles(['build/esm'], {
|
|
25
|
+
root
|
|
26
|
+
})];
|
|
27
|
+
return {
|
|
28
|
+
input: entries,
|
|
29
|
+
plugins,
|
|
30
|
+
onwarn(warning, defaultWarn) {
|
|
31
|
+
// Removes annoying warnings for React-focused libraries that
|
|
32
|
+
// include 'use client' directives.
|
|
33
|
+
if (warning.code === 'MODULE_LEVEL_DIRECTIVE' && /['"]use client['"]/.test(warning.message)) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
defaultWarn(warning);
|
|
37
|
+
},
|
|
38
|
+
output: {
|
|
39
|
+
preserveModules: true,
|
|
40
|
+
preserveModulesRoot: sourceRoot,
|
|
41
|
+
format: 'esm',
|
|
42
|
+
dir: outputDirectory,
|
|
43
|
+
entryFileNames: `[name].mjs`,
|
|
44
|
+
assetFileNames: `[name].[ext]`
|
|
45
|
+
// chunkFileNames: createChunkNamer({
|
|
46
|
+
// extension: ESM_EXTENSION,
|
|
47
|
+
// sourceRoot: sourceRootDirectory,
|
|
48
|
+
// }),
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
async function sourceEntriesForPackage(root, packageJSON) {
|
|
54
|
+
const {
|
|
55
|
+
main,
|
|
56
|
+
exports
|
|
57
|
+
} = packageJSON;
|
|
58
|
+
const entries = {};
|
|
59
|
+
if (typeof main === 'string') {
|
|
60
|
+
entries['.'] = await resolveTargetFileAsSource(main, root);
|
|
61
|
+
}
|
|
62
|
+
if (typeof exports === 'string') {
|
|
63
|
+
entries['.'] = await resolveTargetFileAsSource(exports, root);
|
|
64
|
+
return entries;
|
|
65
|
+
} else if (exports == null || typeof exports !== 'object') {
|
|
66
|
+
return entries;
|
|
67
|
+
}
|
|
68
|
+
for (const [exportPath, exportCondition] of Object.entries(exports)) {
|
|
69
|
+
let targetFile = null;
|
|
70
|
+
if (exportCondition == null) continue;
|
|
71
|
+
if (typeof exportCondition === 'string') {
|
|
72
|
+
targetFile = exportCondition;
|
|
73
|
+
} else {
|
|
74
|
+
targetFile ??= exportCondition['source'] ?? exportCondition['quilt:source'] ?? exportCondition['quilt:esnext'] ?? Object.values(exportCondition).find(condition => typeof condition === 'string' && condition.startsWith('./build/'));
|
|
75
|
+
}
|
|
76
|
+
if (targetFile == null) continue;
|
|
77
|
+
const sourceFile = await resolveTargetFileAsSource(targetFile, root);
|
|
78
|
+
entries[exportPath] = sourceFile;
|
|
79
|
+
}
|
|
80
|
+
return entries;
|
|
81
|
+
}
|
|
82
|
+
async function resolveTargetFileAsSource(file, root) {
|
|
83
|
+
const sourceFile = file.includes('/build/') ? (await glob(file.replace(/[/]build[/][^/]+[/]/, '/*/').replace(/(\.d\.ts|\.[\w]+)$/, '.*'), {
|
|
84
|
+
cwd: root,
|
|
85
|
+
absolute: true,
|
|
86
|
+
ignore: [path.resolve(root, file)]
|
|
87
|
+
}))[0] : path.resolve(root, file);
|
|
88
|
+
return sourceFile;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export { quiltPackageESModules };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as path from 'node:path';
|
|
2
|
+
import { fileURLToPath } from 'node:url';
|
|
3
|
+
import { readFile } from 'node:fs/promises';
|
|
4
|
+
|
|
5
|
+
async function loadPackageJSON(root) {
|
|
6
|
+
const file = await readFile(path.join(fileURLToPath(root), 'package.json'), 'utf8');
|
|
7
|
+
return JSON.parse(file);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export { loadPackageJSON };
|