@quilted/rollup 0.2.5 → 0.2.7
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 +18 -0
- package/build/esm/app.mjs +86 -69
- package/build/esm/features/node.mjs +1 -1
- package/build/esm/module.mjs +36 -17
- package/build/esm/package.mjs +3 -1
- package/build/esm/shared/magic-module.mjs +5 -3
- package/build/esm/shared/project.mjs +3 -0
- package/build/tsconfig.tsbuildinfo +1 -1
- package/build/typescript/app.d.ts +19 -13
- package/build/typescript/app.d.ts.map +1 -1
- package/build/typescript/features/env.d.ts +3 -5
- package/build/typescript/features/env.d.ts.map +1 -1
- package/build/typescript/features/node.d.ts.map +1 -1
- package/build/typescript/features/request-router.d.ts +2 -2
- package/build/typescript/module.d.ts +12 -5
- package/build/typescript/module.d.ts.map +1 -1
- package/build/typescript/package.d.ts.map +1 -1
- package/build/typescript/shared/magic-module.d.ts +3 -3
- package/build/typescript/shared/magic-module.d.ts.map +1 -1
- package/build/typescript/shared/project.d.ts +1 -0
- package/build/typescript/shared/project.d.ts.map +1 -1
- package/package.json +10 -1
- package/source/app.ts +113 -101
- package/source/features/node.ts +4 -1
- package/source/module.ts +48 -19
- package/source/package.ts +2 -0
- package/source/shared/magic-module.ts +10 -4
- package/source/shared/project.ts +4 -0
package/source/module.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {type InputPluginOption, type RollupOptions} from 'rollup';
|
|
2
2
|
|
|
3
|
-
import {Project} from './shared/project.ts';
|
|
3
|
+
import {Project, sourceEntriesForProject} from './shared/project.ts';
|
|
4
4
|
import {
|
|
5
5
|
RollupNodePluginOptions,
|
|
6
6
|
getNodePlugins,
|
|
@@ -21,13 +21,16 @@ export interface ModuleOptions {
|
|
|
21
21
|
|
|
22
22
|
/**
|
|
23
23
|
* The entry module for this module. This should be an absolute path, or relative
|
|
24
|
-
* path from the root directory containing your project.
|
|
25
|
-
*
|
|
26
|
-
*
|
|
24
|
+
* path from the root directory containing your project. It can also be an object, where
|
|
25
|
+
* each key is the name of an entry into the module, and each value is the path to the
|
|
26
|
+
* source path for that entry. If not provided, this defaults the detected source files for
|
|
27
|
+
* the the `exports` field in your package.json, then to the `main` field in your package.json,
|
|
28
|
+
* then to a file `index`, `module`, `entry`, or `input` in your project’s root directory.
|
|
27
29
|
*
|
|
28
30
|
* @example './my-module.tsx'
|
|
31
|
+
* @example {browser: './browser.tsx', server: './server.tsx'}
|
|
29
32
|
*/
|
|
30
|
-
entry?: string
|
|
33
|
+
entry?: string | Record<string, string>;
|
|
31
34
|
|
|
32
35
|
/**
|
|
33
36
|
* Whether to include GraphQL-related code transformations.
|
|
@@ -55,6 +58,7 @@ export interface ModuleAssetsOptions
|
|
|
55
58
|
* @default true
|
|
56
59
|
*/
|
|
57
60
|
minify?: boolean;
|
|
61
|
+
clean?: boolean;
|
|
58
62
|
hash?: boolean | 'async-only';
|
|
59
63
|
targets?: BrowserGroupTargetSelection;
|
|
60
64
|
}
|
|
@@ -110,7 +114,6 @@ export async function quiltModule({
|
|
|
110
114
|
monorepoPackageAliases({root: project.root}),
|
|
111
115
|
esnext({mode, targets: browserGroup.browsers}),
|
|
112
116
|
react(),
|
|
113
|
-
removeBuildFiles(['build/assets', 'build/reports'], {root: project.root}),
|
|
114
117
|
];
|
|
115
118
|
|
|
116
119
|
if (graphql) {
|
|
@@ -123,6 +126,14 @@ export async function quiltModule({
|
|
|
123
126
|
plugins.push(minify());
|
|
124
127
|
}
|
|
125
128
|
|
|
129
|
+
if (assets?.clean ?? true) {
|
|
130
|
+
plugins.push(
|
|
131
|
+
removeBuildFiles(['build/assets', 'build/reports'], {
|
|
132
|
+
root: project.root,
|
|
133
|
+
}),
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
|
|
126
137
|
plugins.push(
|
|
127
138
|
visualizer({
|
|
128
139
|
template: 'treemap',
|
|
@@ -152,30 +163,48 @@ export async function quiltModule({
|
|
|
152
163
|
generatedCode: await rollupGenerateOptionsForBrowsers(
|
|
153
164
|
browserGroup.browsers,
|
|
154
165
|
),
|
|
166
|
+
minifyInternalExports: minify,
|
|
155
167
|
},
|
|
156
168
|
} satisfies RollupOptions;
|
|
157
169
|
}
|
|
158
170
|
|
|
159
|
-
async function resolveModuleEntry(
|
|
171
|
+
async function resolveModuleEntry(
|
|
172
|
+
entry: string | Record<string, string> | undefined,
|
|
173
|
+
project: Project,
|
|
174
|
+
) {
|
|
160
175
|
if (entry) {
|
|
161
|
-
|
|
176
|
+
if (typeof entry === 'string') {
|
|
177
|
+
const absolutePath = project.resolve(entry);
|
|
178
|
+
return {[project.relative(absolutePath)]: absolutePath};
|
|
179
|
+
} else {
|
|
180
|
+
return Object.fromEntries(
|
|
181
|
+
Object.entries(entry).map(([key, value]) => [
|
|
182
|
+
normalizeEntryName(key),
|
|
183
|
+
project.resolve(value),
|
|
184
|
+
]),
|
|
185
|
+
);
|
|
186
|
+
}
|
|
162
187
|
}
|
|
163
188
|
|
|
164
|
-
const
|
|
189
|
+
const entries = await sourceEntriesForProject(project);
|
|
190
|
+
const entryArray = Object.entries(entries);
|
|
165
191
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
192
|
+
if (entryArray.length > 0) {
|
|
193
|
+
return Object.fromEntries(
|
|
194
|
+
entryArray.map(([key, value]) => [normalizeEntryName(key), value]),
|
|
195
|
+
);
|
|
170
196
|
}
|
|
171
197
|
|
|
172
|
-
const
|
|
173
|
-
'{index,module,entry,input}.{ts,tsx,mjs,js,jsx}',
|
|
174
|
-
{
|
|
198
|
+
const sourceFile = (
|
|
199
|
+
await project.glob('{index,module,entry,input}.{ts,tsx,mjs,js,jsx}', {
|
|
175
200
|
nodir: true,
|
|
176
201
|
absolute: true,
|
|
177
|
-
}
|
|
178
|
-
)
|
|
202
|
+
})
|
|
203
|
+
)[0]!;
|
|
204
|
+
|
|
205
|
+
return {[normalizeEntryName(project.relative(sourceFile))]: sourceFile};
|
|
206
|
+
}
|
|
179
207
|
|
|
180
|
-
|
|
208
|
+
function normalizeEntryName(name: string) {
|
|
209
|
+
return name === '.' ? 'index' : name.startsWith('./') ? name.slice(2) : name;
|
|
181
210
|
}
|
package/source/package.ts
CHANGED
|
@@ -237,6 +237,7 @@ export async function quiltPackageESModules({
|
|
|
237
237
|
entryFileNames: `[name].mjs`,
|
|
238
238
|
assetFileNames: `[name].[ext]`,
|
|
239
239
|
generatedCode,
|
|
240
|
+
minifyInternalExports: false,
|
|
240
241
|
// We only want to preserve the original directory structure if there
|
|
241
242
|
// are actual package entries.
|
|
242
243
|
...(hasEntries
|
|
@@ -257,6 +258,7 @@ export async function quiltPackageESModules({
|
|
|
257
258
|
preserveModules: true,
|
|
258
259
|
preserveModulesRoot: source.root,
|
|
259
260
|
generatedCode,
|
|
261
|
+
minifyInternalExports: false,
|
|
260
262
|
});
|
|
261
263
|
}
|
|
262
264
|
|
|
@@ -11,24 +11,30 @@ export function createMagicModulePlugin({
|
|
|
11
11
|
sideEffects = false,
|
|
12
12
|
}: {
|
|
13
13
|
readonly name: string;
|
|
14
|
-
readonly alias?: string;
|
|
14
|
+
readonly alias?: string | (() => string | Promise<string>);
|
|
15
15
|
readonly module: string;
|
|
16
16
|
readonly sideEffects?: boolean;
|
|
17
17
|
source?(this: PluginContext): string | Promise<string>;
|
|
18
18
|
}) {
|
|
19
|
+
const virtualModuleAlias = `${VIRTUAL_MODULE_PREFIX}${module}${VIRTUAL_MODULE_POSTFIX}`;
|
|
20
|
+
|
|
19
21
|
return {
|
|
20
22
|
name,
|
|
21
|
-
resolveId(id) {
|
|
23
|
+
async resolveId(id) {
|
|
22
24
|
if (id !== module) return null;
|
|
23
25
|
|
|
26
|
+
const resolved =
|
|
27
|
+
(typeof alias === 'function' ? await alias() : alias) ??
|
|
28
|
+
virtualModuleAlias;
|
|
29
|
+
|
|
24
30
|
return {
|
|
25
|
-
id:
|
|
31
|
+
id: resolved,
|
|
26
32
|
moduleSideEffects: sideEffects ? 'no-treeshake' : undefined,
|
|
27
33
|
};
|
|
28
34
|
},
|
|
29
35
|
load: getSource
|
|
30
36
|
? async function load(source) {
|
|
31
|
-
if (source !==
|
|
37
|
+
if (source !== virtualModuleAlias) return null;
|
|
32
38
|
|
|
33
39
|
const code = await getSource.call(this);
|
|
34
40
|
|
package/source/shared/project.ts
CHANGED