@quilted/rollup 0.1.19 → 0.2.1

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.
Files changed (129) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/build/esm/app.mjs +450 -222
  3. package/build/esm/constants.mjs +5 -5
  4. package/build/esm/features/assets.mjs +93 -81
  5. package/build/esm/features/async.mjs +186 -0
  6. package/build/esm/features/css.mjs +26 -39
  7. package/build/esm/features/env.mjs +47 -44
  8. package/build/esm/features/esnext.mjs +57 -0
  9. package/build/esm/features/graphql/transform.mjs +60 -56
  10. package/build/esm/features/graphql.mjs +65 -47
  11. package/build/esm/features/request-router.mjs +6 -4
  12. package/build/esm/features/source-code.mjs +54 -28
  13. package/build/esm/features/system-js.mjs +29 -20
  14. package/build/esm/features/typescript.mjs +13 -10
  15. package/build/esm/features/workers.mjs +173 -0
  16. package/build/esm/index.mjs +3 -2
  17. package/build/esm/module.mjs +69 -62
  18. package/build/esm/package.mjs +275 -84
  19. package/build/esm/server.mjs +118 -0
  20. package/build/esm/shared/browserslist.mjs +141 -16
  21. package/build/esm/shared/magic-module.mjs +9 -7
  22. package/build/esm/shared/package-json.mjs +7 -1
  23. package/build/esm/shared/path.mjs +7 -0
  24. package/build/esm/shared/rollup.mjs +89 -25
  25. package/build/esm/shared/strings.mjs +7 -6
  26. package/build/tsconfig.tsbuildinfo +1 -1
  27. package/build/typescript/app.d.ts +132 -29
  28. package/build/typescript/app.d.ts.map +1 -1
  29. package/build/typescript/features/assets.d.ts +1 -2
  30. package/build/typescript/features/assets.d.ts.map +1 -1
  31. package/build/typescript/features/async.d.ts +10 -0
  32. package/build/typescript/features/async.d.ts.map +1 -0
  33. package/build/typescript/features/css.d.ts +2 -1
  34. package/build/typescript/features/css.d.ts.map +1 -1
  35. package/build/typescript/features/env.d.ts +1 -0
  36. package/build/typescript/features/env.d.ts.map +1 -1
  37. package/build/typescript/features/esnext.d.ts +9 -0
  38. package/build/typescript/features/esnext.d.ts.map +1 -0
  39. package/build/typescript/features/graphql.d.ts +2 -2
  40. package/build/typescript/features/graphql.d.ts.map +1 -1
  41. package/build/typescript/features/source-code.d.ts +9 -3
  42. package/build/typescript/features/source-code.d.ts.map +1 -1
  43. package/build/typescript/features/system-js.d.ts +4 -1
  44. package/build/typescript/features/system-js.d.ts.map +1 -1
  45. package/build/typescript/features/workers.d.ts +52 -0
  46. package/build/typescript/features/workers.d.ts.map +1 -0
  47. package/build/typescript/index.d.ts +3 -2
  48. package/build/typescript/index.d.ts.map +1 -1
  49. package/build/typescript/module.d.ts +24 -6
  50. package/build/typescript/module.d.ts.map +1 -1
  51. package/build/typescript/package.d.ts +196 -4
  52. package/build/typescript/package.d.ts.map +1 -1
  53. package/build/typescript/server.d.ts +98 -0
  54. package/build/typescript/server.d.ts.map +1 -0
  55. package/build/typescript/shared/browserslist.d.ts +20 -3
  56. package/build/typescript/shared/browserslist.d.ts.map +1 -1
  57. package/build/typescript/shared/path.d.ts +2 -0
  58. package/build/typescript/shared/path.d.ts.map +1 -0
  59. package/build/typescript/shared/rollup.d.ts +27 -1
  60. package/build/typescript/shared/rollup.d.ts.map +1 -1
  61. package/configuration/rollup.config.js +40 -0
  62. package/package.json +62 -9
  63. package/source/app.ts +475 -99
  64. package/source/features/assets.ts +5 -7
  65. package/source/features/async.ts +249 -0
  66. package/source/features/css.ts +4 -2
  67. package/source/features/env.ts +6 -0
  68. package/source/features/esnext.ts +70 -0
  69. package/source/features/graphql.ts +4 -2
  70. package/source/features/source-code.ts +27 -9
  71. package/source/features/system-js.ts +25 -2
  72. package/source/features/workers.ts +292 -0
  73. package/source/index.ts +4 -0
  74. package/source/module.ts +45 -19
  75. package/source/package.ts +394 -36
  76. package/source/server.ts +245 -0
  77. package/source/shared/browserslist.ts +208 -18
  78. package/source/shared/path.ts +5 -0
  79. package/source/shared/rollup.ts +102 -4
  80. package/tsconfig.json +6 -2
  81. package/build/cjs/app.cjs +0 -441
  82. package/build/cjs/constants.cjs +0 -13
  83. package/build/cjs/features/assets.cjs +0 -240
  84. package/build/cjs/features/css.cjs +0 -71
  85. package/build/cjs/features/env.cjs +0 -135
  86. package/build/cjs/features/graphql/transform.cjs +0 -186
  87. package/build/cjs/features/graphql.cjs +0 -86
  88. package/build/cjs/features/request-router.cjs +0 -31
  89. package/build/cjs/features/source-code.cjs +0 -54
  90. package/build/cjs/features/system-js.cjs +0 -36
  91. package/build/cjs/features/typescript.cjs +0 -56
  92. package/build/cjs/index.cjs +0 -13
  93. package/build/cjs/module.cjs +0 -121
  94. package/build/cjs/package.cjs +0 -170
  95. package/build/cjs/shared/browserslist.cjs +0 -25
  96. package/build/cjs/shared/magic-module.cjs +0 -32
  97. package/build/cjs/shared/package-json.cjs +0 -31
  98. package/build/cjs/shared/rollup.cjs +0 -72
  99. package/build/cjs/shared/strings.cjs +0 -16
  100. package/build/esnext/app.esnext +0 -414
  101. package/build/esnext/constants.esnext +0 -7
  102. package/build/esnext/features/assets.esnext +0 -215
  103. package/build/esnext/features/css.esnext +0 -69
  104. package/build/esnext/features/env.esnext +0 -112
  105. package/build/esnext/features/graphql/transform.esnext +0 -181
  106. package/build/esnext/features/graphql.esnext +0 -84
  107. package/build/esnext/features/request-router.esnext +0 -29
  108. package/build/esnext/features/source-code.esnext +0 -51
  109. package/build/esnext/features/system-js.esnext +0 -33
  110. package/build/esnext/features/typescript.esnext +0 -34
  111. package/build/esnext/index.esnext +0 -3
  112. package/build/esnext/module.esnext +0 -100
  113. package/build/esnext/package.esnext +0 -148
  114. package/build/esnext/shared/browserslist.esnext +0 -23
  115. package/build/esnext/shared/magic-module.esnext +0 -30
  116. package/build/esnext/shared/package-json.esnext +0 -10
  117. package/build/esnext/shared/rollup.esnext +0 -49
  118. package/build/esnext/shared/strings.esnext +0 -14
  119. package/build/typescript/env.d.ts +0 -55
  120. package/build/typescript/env.d.ts.map +0 -1
  121. package/build/typescript/graphql/transform.d.ts +0 -17
  122. package/build/typescript/graphql/transform.d.ts.map +0 -1
  123. package/build/typescript/graphql.d.ts +0 -6
  124. package/build/typescript/graphql.d.ts.map +0 -1
  125. package/build/typescript/request-router.d.ts +0 -15
  126. package/build/typescript/request-router.d.ts.map +0 -1
  127. package/build/typescript/shared/source-code.d.ts +0 -5
  128. package/build/typescript/shared/source-code.d.ts.map +0 -1
  129. package/quilt.project.ts +0 -5
@@ -1,112 +0,0 @@
1
- import * as path from 'node:path';
2
- import * as fs from 'node:fs';
3
- import { MAGIC_MODULE_ENV } from '../constants.esnext';
4
- import { multiline } from '../shared/strings.esnext';
5
- import { smartReplace } from '../shared/rollup.esnext';
6
- import { createMagicModulePlugin } from '../shared/magic-module.esnext';
7
-
8
- const EMPTY_PROCESS_ENV_OBJECT = {
9
- 'globalThis.process.env.': `({}).`,
10
- 'global.process.env.': `({}).`,
11
- 'process.env.': `({}).`
12
- };
13
- function replaceProcessEnv({
14
- mode,
15
- preserve = true
16
- }) {
17
- return smartReplace({
18
- // @see https://github.com/vitejs/vite/blob/2b1ffe86328f9d06ef9528ee117b61889893ddcc/packages/vite/src/node/plugins/define.ts#L112
19
- 'globalThis.process.env.NODE_ENV': JSON.stringify(mode),
20
- 'global.process.env.NODE_ENV': JSON.stringify(mode),
21
- 'process.env.NODE_ENV': JSON.stringify(mode),
22
- ...(preserve ? {} : EMPTY_PROCESS_ENV_OBJECT)
23
- });
24
- }
25
- function magicModuleEnv({
26
- mode,
27
- dotenv = {
28
- roots: ['.', 'configuration']
29
- },
30
- inline = [],
31
- runtime = '{}'
32
- } = {}) {
33
- return createMagicModulePlugin({
34
- name: '@quilted/magic-module/env',
35
- module: MAGIC_MODULE_ENV,
36
- async source() {
37
- const inlineEnv = {};
38
- if (mode) {
39
- inlineEnv.MODE = mode;
40
- }
41
- const loadedEnv = await loadEnv.call(this, {
42
- mode,
43
- dotenv
44
- });
45
- for (const inlineVariable of inline.sort()) {
46
- if (inlineVariable in inlineEnv) continue;
47
- const value = process.env[inlineVariable] ?? loadedEnv[inlineVariable];
48
- if (value == null) continue;
49
- inlineEnv[inlineVariable] = typeof value === 'string' && value[0] === '"' && value[value.length - 1] === '"' ? JSON.parse(value) : value;
50
- }
51
- return multiline`
52
- const runtime = (${runtime});
53
- const inline = JSON.parse(${JSON.stringify(JSON.stringify(inlineEnv))});
54
-
55
- const Env = new Proxy(
56
- {},
57
- {
58
- get(_, property) {
59
- return runtime[property] ?? inline[property];
60
- },
61
- },
62
- );
63
-
64
- export default Env;
65
- `;
66
- }
67
- });
68
- }
69
-
70
- // Inspired by https://github.com/vitejs/vite/blob/e0a4d810598d1834933ed437ac5a2168cbbbf2f8/packages/vite/source/node/config.ts#L1050-L1113
71
- async function loadEnv({
72
- mode,
73
- dotenv
74
- }) {
75
- const env = {
76
- ...process.env
77
- };
78
- if (dotenv !== false) {
79
- const {
80
- parse
81
- } = await import('dotenv');
82
- let files = dotenv.files;
83
- if (files == null) {
84
- const testFiles = [
85
- // default file
86
- `.env`,
87
- // local file
88
- `.env.local`];
89
- if (mode) {
90
- testFiles.push(
91
- // mode file
92
- `.env.${mode}`,
93
- // mode local file
94
- `.env.${mode}.local`);
95
- }
96
- files = testFiles.flatMap(file => (dotenv.roots ?? ['.', 'configuration']).map(root => path.resolve(root, file)));
97
- }
98
- const envFileResults = await Promise.all(files.map(async file => {
99
- if (fs.existsSync(file)) {
100
- this.addWatchFile(file);
101
- return parse(await fs.promises.readFile(file, 'utf-8'));
102
- }
103
- }));
104
- for (const envFileResult of envFileResults) {
105
- if (envFileResult == null) continue;
106
- Object.assign(env, envFileResult);
107
- }
108
- }
109
- return env;
110
- }
111
-
112
- export { magicModuleEnv, replaceProcessEnv };
@@ -1,181 +0,0 @@
1
- import { createHash } from 'node:crypto';
2
- import { print, parse } from 'graphql';
3
-
4
- const IMPORT_REGEX = /^#import\s+['"]([^'"]*)['"];?[\s\n]*/gm;
5
- const DEFAULT_NAME = 'Operation';
6
- function cleanGraphQLDocument(document, {
7
- removeUnused = true
8
- } = {}) {
9
- if (removeUnused) {
10
- removeUnusedDefinitions(document, {
11
- exclude: removeUnused === true ? new Set() : removeUnused.exclude
12
- });
13
- }
14
- for (const definition of document.definitions) {
15
- addTypename(definition);
16
- }
17
- const normalizedSource = minifyGraphQLSource(print(document));
18
- const normalizedDocument = parse(normalizedSource);
19
- for (const definition of normalizedDocument.definitions) {
20
- stripLoc(definition);
21
- }
22
-
23
- // This ID is a hash of the full file contents that are part of the document,
24
- // including other documents that are injected in, but excluding any unused
25
- // fragments. This is useful for things like persisted queries.
26
- const id = createHash('sha256').update(normalizedSource).digest('hex');
27
- Reflect.defineProperty(normalizedDocument, 'id', {
28
- value: id,
29
- enumerable: true,
30
- writable: false,
31
- configurable: false
32
- });
33
- Reflect.defineProperty(normalizedDocument, 'loc', {
34
- value: stripDocumentLoc(normalizedDocument.loc),
35
- enumerable: true,
36
- writable: false,
37
- configurable: false
38
- });
39
- return normalizedDocument;
40
- }
41
- function extractGraphQLImports(rawSource) {
42
- const imports = new Set();
43
- const source = rawSource.replace(IMPORT_REGEX, (_, imported) => {
44
- imports.add(imported);
45
- return '';
46
- });
47
- return {
48
- imports: [...imports],
49
- source
50
- };
51
- }
52
- function toGraphQLOperation(documentOrSource) {
53
- const document = typeof documentOrSource === 'string' ? cleanGraphQLDocument(parse(documentOrSource)) : documentOrSource;
54
- return {
55
- id: document.id,
56
- name: operationNameForDocument(document),
57
- source: document.loc.source.body
58
- };
59
- }
60
- function operationNameForDocument(document) {
61
- return document.definitions.find(definition => definition.kind === 'OperationDefinition')?.name?.value;
62
- }
63
- function removeUnusedDefinitions(document, {
64
- exclude
65
- }) {
66
- const usedDefinitions = new Set();
67
- const dependencies = definitionDependencies(document.definitions);
68
- const markAsUsed = definition => {
69
- if (usedDefinitions.has(definition)) {
70
- return;
71
- }
72
- usedDefinitions.add(definition);
73
- for (const dependency of dependencies.get(definition) || []) {
74
- markAsUsed(dependency);
75
- }
76
- };
77
- for (const definition of document.definitions) {
78
- if (definition.kind === 'FragmentDefinition') {
79
- if (exclude.has(definition.name.value)) {
80
- markAsUsed(definition);
81
- }
82
- } else {
83
- markAsUsed(definition);
84
- }
85
- }
86
- document.definitions = [...usedDefinitions];
87
- }
88
- function definitionDependencies(definitions) {
89
- const executableDefinitions = definitions.filter(definition => definition.kind === 'OperationDefinition' || definition.kind === 'FragmentDefinition');
90
- const definitionsByName = new Map(executableDefinitions.map(definition => [definition.name ? definition.name.value : DEFAULT_NAME, definition]));
91
- return new Map(executableDefinitions.map(executableNode => [executableNode, [...collectUsedFragmentSpreads(executableNode, new Set())].map(usedFragment => {
92
- const definition = definitionsByName.get(usedFragment);
93
- if (definition == null) {
94
- throw new Error(`You attempted to use the fragment '${usedFragment}' (in '${executableNode.name ? executableNode.name.value : DEFAULT_NAME}'), but it does not exist. Maybe you forgot to import it from another document?`);
95
- }
96
- return definition;
97
- })]));
98
- }
99
- const TYPENAME_FIELD = {
100
- kind: 'Field',
101
- alias: null,
102
- name: {
103
- kind: 'Name',
104
- value: '__typename'
105
- }
106
- };
107
- function addTypename(definition) {
108
- for (const {
109
- selections
110
- } of selectionSetsForDefinition(definition)) {
111
- const hasTypename = selections.some(selection => selection.kind === 'Field' && selection.name.value === '__typename');
112
- if (!hasTypename) {
113
- selections.push(TYPENAME_FIELD);
114
- }
115
- }
116
- }
117
- function collectUsedFragmentSpreads(definition, usedSpreads) {
118
- for (const selection of selectionsForDefinition(definition)) {
119
- if (selection.kind === 'FragmentSpread') {
120
- usedSpreads.add(selection.name.value);
121
- }
122
- }
123
- return usedSpreads;
124
- }
125
- function selectionsForDefinition(definition) {
126
- if (!('selectionSet' in definition) || definition.selectionSet == null) {
127
- return [][Symbol.iterator]();
128
- }
129
- return selectionsForSelectionSet(definition.selectionSet);
130
- }
131
- function* selectionSetsForDefinition(definition) {
132
- if (!('selectionSet' in definition) || definition.selectionSet == null) {
133
- return [][Symbol.iterator]();
134
- }
135
- if (definition.kind !== 'OperationDefinition') {
136
- yield definition.selectionSet;
137
- }
138
- for (const nestedSelection of selectionsForDefinition(definition)) {
139
- if ('selectionSet' in nestedSelection && nestedSelection.selectionSet != null) {
140
- yield nestedSelection.selectionSet;
141
- }
142
- }
143
- }
144
- function* selectionsForSelectionSet({
145
- selections
146
- }) {
147
- for (const selection of selections) {
148
- yield selection;
149
- if ('selectionSet' in selection && selection.selectionSet != null) {
150
- yield* selectionsForSelectionSet(selection.selectionSet);
151
- }
152
- }
153
- }
154
- function stripDocumentLoc(loc) {
155
- const normalizedLoc = {
156
- ...loc
157
- };
158
- delete normalizedLoc.endToken;
159
- delete normalizedLoc.startToken;
160
- return normalizedLoc;
161
- }
162
- function stripLoc(value) {
163
- if (Array.isArray(value)) {
164
- value.forEach(stripLoc);
165
- } else if (typeof value === 'object') {
166
- if (value == null) {
167
- return;
168
- }
169
- if ('loc' in value) {
170
- delete value.loc;
171
- }
172
- for (const key of Object.keys(value)) {
173
- stripLoc(value[key]);
174
- }
175
- }
176
- }
177
- function minifyGraphQLSource(source) {
178
- return source.replace(/#.*/g, '').replace(/\\n/g, ' ').replace(/\s\s+/g, ' ').replace(/\s*({|}|\(|\)|\.|:|,)\s*/g, '$1');
179
- }
180
-
181
- export { cleanGraphQLDocument, extractGraphQLImports, minifyGraphQLSource, toGraphQLOperation };
@@ -1,84 +0,0 @@
1
- import { dirname } from 'node:path';
2
- import { mkdir, writeFile, readFile } from 'node:fs/promises';
3
- import { parse } from 'graphql';
4
- import { toGraphQLOperation, cleanGraphQLDocument, extractGraphQLImports } from './graphql/transform.esnext';
5
-
6
- function graphql({
7
- manifest
8
- } = {}) {
9
- const shouldWriteManifest = Boolean(manifest);
10
- const manifestPath = typeof manifest === 'string' ? manifest : `manifests/graphql.json`;
11
- return {
12
- name: '@quilted/graphql',
13
- async transform(code, id) {
14
- if (!id.endsWith('.graphql') && !id.endsWith('.gql')) return null;
15
- const topLevelDefinitions = new Set();
16
- const loadedDocument = await loadDocument(code, id, this, (document, level) => {
17
- if (level !== 0) return;
18
- for (const definition of document.definitions) {
19
- if ('name' in definition && definition.name != null) {
20
- topLevelDefinitions.add(definition.name.value);
21
- }
22
- }
23
- });
24
- const document = toGraphQLOperation(cleanGraphQLDocument(loadedDocument, {
25
- removeUnused: {
26
- exclude: topLevelDefinitions
27
- }
28
- }));
29
- return {
30
- code: `export default JSON.parse(${JSON.stringify(JSON.stringify(document))})`,
31
- meta: shouldWriteManifest ? {
32
- quilt: {
33
- graphql: document
34
- }
35
- } : undefined
36
- };
37
- },
38
- async generateBundle() {
39
- if (!shouldWriteManifest) return;
40
- const operations = {};
41
- for (const moduleId of this.getModuleIds()) {
42
- const operation = this.getModuleInfo(moduleId)?.meta?.quilt?.graphql;
43
- if (operation != null && typeof operation.id === 'string' && typeof operation.source === 'string') {
44
- operations[operation.id] = operation.source;
45
- }
46
- }
47
- await mkdir(dirname(manifestPath), {
48
- recursive: true
49
- });
50
- await writeFile(manifestPath, JSON.stringify(operations, null, 2));
51
- }
52
- };
53
- }
54
- async function loadDocument(code, file, plugin, add, level = 0, seen = new Set()) {
55
- const {
56
- imports,
57
- source
58
- } = extractGraphQLImports(code);
59
- const document = parse(source);
60
- add?.(document, level);
61
- if (imports.length === 0) {
62
- return document;
63
- }
64
- const resolvedImports = await Promise.all(imports.map(async imported => {
65
- if (seen.has(imported)) return;
66
- seen.add(imported);
67
- const resolvedId = await plugin.resolve(imported, file);
68
- if (resolvedId == null) {
69
- throw new Error(`Could not find ${JSON.stringify(imported)} from ${JSON.stringify(file)}`);
70
- }
71
- plugin.addWatchFile(resolvedId.id);
72
- const contents = await readFile(resolvedId.id, {
73
- encoding: 'utf8'
74
- });
75
- return loadDocument(contents, resolvedId.id, plugin, add, level + 1, seen);
76
- }));
77
- for (const importedDocument of resolvedImports) {
78
- if (importedDocument == null) continue;
79
- document.definitions.push(...importedDocument.definitions);
80
- }
81
- return document;
82
- }
83
-
84
- export { graphql };
@@ -1,29 +0,0 @@
1
- import { MAGIC_MODULE_ENTRY, MAGIC_MODULE_REQUEST_ROUTER } from '../constants.esnext';
2
- import { createMagicModulePlugin } from '../shared/magic-module.esnext';
3
- import { multiline } from '../shared/strings.esnext';
4
-
5
- function magicModuleRequestRouterEntry({
6
- host,
7
- port
8
- } = {}) {
9
- return createMagicModulePlugin({
10
- name: '@quilted/request-router',
11
- sideEffects: true,
12
- module: MAGIC_MODULE_ENTRY,
13
- async source() {
14
- const initialContent = multiline`
15
- import requestRouter from ${JSON.stringify(MAGIC_MODULE_REQUEST_ROUTER)};
16
-
17
- import {createHttpServer} from '@quilted/quilt/request-router/node';
18
-
19
- const port = ${port ?? 'Number.parseInt(process.env.PORT, 10)'};
20
- const host = ${host ? JSON.stringify(host) : 'process.env.HOST'};
21
-
22
- createHttpServer(requestRouter).listen(port, host);
23
- `;
24
- return initialContent;
25
- }
26
- });
27
- }
28
-
29
- export { magicModuleRequestRouterEntry };
@@ -1,51 +0,0 @@
1
- import { createRequire } from 'node:module';
2
- import babel from '@rollup/plugin-babel';
3
- import esbuild from 'rollup-plugin-esbuild';
4
-
5
- const require = createRequire(import.meta.url);
6
- function sourceCode({
7
- mode,
8
- targets,
9
- babel: useBabel = true
10
- }) {
11
- if (!useBabel) {
12
- return esbuild({
13
- // Support very modern features
14
- target: 'es2022',
15
- jsx: 'automatic',
16
- jsxImportSource: 'react',
17
- exclude: 'node_modules/**'
18
- });
19
- }
20
- return babel({
21
- envName: mode,
22
- configFile: false,
23
- babelrc: false,
24
- presets: [require.resolve('@babel/preset-typescript'), [require.resolve('@babel/preset-react'), {
25
- runtime: 'automatic',
26
- importSource: 'react',
27
- development: mode === 'development'
28
- }], [require.resolve('@babel/preset-env'), {
29
- useBuiltIns: false,
30
- bugfixes: true,
31
- shippedProposals: true
32
- // I thought I wanted this, but it seems to break the `targets` option
33
- // passed as a root argument.
34
- // ignoreBrowserslistConfig: targets != null,
35
- }]],
36
-
37
- plugins: [[require.resolve('@babel/plugin-proposal-decorators'), {
38
- version: '2023-01'
39
- }]],
40
- extensions: ['.ts', '.tsx', '.mts', '.mtsx', '.js', '.jsx', '.es6', '.es', '.mjs'],
41
- exclude: 'node_modules/**',
42
- babelHelpers: 'bundled',
43
- skipPreflightCheck: true,
44
- // Babel doesn’t like this option being set to `undefined`.
45
- ...(targets ? {
46
- targets
47
- } : {})
48
- });
49
- }
50
-
51
- export { sourceCode };
@@ -1,33 +0,0 @@
1
- import { readFile } from 'node:fs/promises';
2
- import { createRequire } from 'node:module';
3
-
4
- function systemJS({
5
- minify = false
6
- } = {}) {
7
- return {
8
- name: '@quilted/system-js',
9
- async renderChunk(_, chunk, options) {
10
- if (options.format !== 'system' || !chunk.isEntry) return null;
11
- const require = createRequire(import.meta.url);
12
- const systemjs = minify ? require.resolve('systemjs/dist/s.min.js') : require.resolve('systemjs/dist/s.js');
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.
17
- const fileHandle = this.emitFile({
18
- type: 'asset',
19
- name: 'loader.js',
20
- source: (await readFile(systemjs, {
21
- encoding: 'utf8'
22
- })).replace(
23
- // Remove the source map comment, if it is present, because we don’t upload the
24
- // sourcemap for this file.
25
- /\n?[/][/]# sourceMappingURL=s.*\.map\n?$/, '')
26
- });
27
- chunk.imports.unshift(this.getFileName(fileHandle));
28
- return null;
29
- }
30
- };
31
- }
32
-
33
- export { systemJS };
@@ -1,34 +0,0 @@
1
- import * as path from 'node:path';
2
- import * as fs from 'node:fs';
3
-
4
- async function createTSConfigAliasPlugin({
5
- root = process.cwd()
6
- } = {}) {
7
- const [{
8
- default: alias
9
- }, tsconfig] = await Promise.all([import('@rollup/plugin-alias'), getTSConfig(root)]);
10
- const tsconfigPaths = tsconfig?.compilerOptions?.paths;
11
- if (tsconfigPaths == null) return undefined;
12
- return alias({
13
- entries: Object.entries(tsconfigPaths).map(([name, aliases]) => {
14
- return {
15
- find: name.includes('*') ? new RegExp(`^${name.replace(/\*/, '(.*)')}$`) : name,
16
- replacement: aliases[0].replace('*', '$1')
17
- };
18
- })
19
- });
20
- }
21
- async function getTSConfig(root) {
22
- const tsconfigPath = path.join(root, 'tsconfig.json');
23
- if (!fs.existsSync(tsconfigPath)) {
24
- return undefined;
25
- }
26
- try {
27
- const tsconfig = JSON.parse(await fs.promises.readFile(tsconfigPath, 'utf8'));
28
- return tsconfig;
29
- } catch {
30
- // intentional noop
31
- }
32
- }
33
-
34
- export { createTSConfigAliasPlugin };
@@ -1,3 +0,0 @@
1
- export { quiltAppBrowser, quiltAppServer } from './app.esnext';
2
- export { quiltModule } from './module.esnext';
3
- export { quiltPackageESModules, quiltPackageESNext } from './package.esnext';
@@ -1,100 +0,0 @@
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
- import { getBrowserTargetDetails } from './shared/browserslist.esnext';
7
-
8
- async function quiltModule({
9
- root: rootPath = process.cwd(),
10
- env,
11
- assets,
12
- graphql = true
13
- } = {}) {
14
- const root = typeof rootPath === 'string' ? rootPath : fileURLToPath(rootPath);
15
- const mode = (typeof env === 'object' ? env?.mode : undefined) ?? 'production';
16
- const outputDirectory = path.join(root, 'build/assets');
17
- const minify = assets?.minify ?? true;
18
- const hash = assets?.hash ?? 'async-only';
19
- const browserTarget = await getBrowserTargetDetails(assets?.targets, {
20
- root
21
- });
22
- const targetFilenamePart = browserTarget.name ? `.${browserTarget.name}` : '';
23
- const [{
24
- visualizer
25
- }, {
26
- magicModuleEnv,
27
- replaceProcessEnv
28
- }, {
29
- sourceCode
30
- }, nodePlugins, packageJSON] = await Promise.all([import('rollup-plugin-visualizer'), import('./features/env.esnext'), import('./features/source-code.esnext'), getNodePlugins(), loadPackageJSON(root)]);
31
- const source = await sourceForModule(root, packageJSON);
32
- const plugins = [...nodePlugins, replaceProcessEnv({
33
- mode
34
- }), magicModuleEnv({
35
- ...env,
36
- mode
37
- }), sourceCode({
38
- mode: 'production',
39
- targets: browserTarget.browsers
40
- }), removeBuildFiles(['build/assets', 'build/reports'], {
41
- root
42
- })];
43
- if (graphql) {
44
- const {
45
- graphql
46
- } = await import('./features/graphql.esnext');
47
- plugins.push(graphql({
48
- manifest: false
49
- }));
50
- }
51
- if (minify) {
52
- const {
53
- minify
54
- } = await import('rollup-plugin-esbuild');
55
- plugins.push(minify());
56
- }
57
- plugins.push(visualizer({
58
- template: 'treemap',
59
- open: false,
60
- brotliSize: true,
61
- filename: path.resolve(root, `build/reports/bundle-visualizer${targetFilenamePart}.html`)
62
- }));
63
- return {
64
- input: source,
65
- plugins,
66
- onwarn(warning, defaultWarn) {
67
- // Removes annoying warnings for React-focused libraries that
68
- // include 'use client' directives.
69
- if (warning.code === 'MODULE_LEVEL_DIRECTIVE' && /['"]use client['"]/.test(warning.message)) {
70
- return;
71
- }
72
- defaultWarn(warning);
73
- },
74
- output: {
75
- format: 'esm',
76
- dir: outputDirectory,
77
- entryFileNames: `[name]${targetFilenamePart}${hash === true ? `.[hash]` : ''}.js`,
78
- chunkFileNames: `[name]${targetFilenamePart}${hash === true || hash === 'async-only' ? `.[hash]` : ''}.js`,
79
- assetFileNames: `[name]${targetFilenamePart}${hash === true ? `.[hash]` : ''}.[ext]`
80
- }
81
- };
82
- }
83
- async function sourceForModule(root, packageJSON) {
84
- const {
85
- main,
86
- exports
87
- } = packageJSON;
88
- const entryFromPackageJSON = main ?? exports?.['.'];
89
- if (entryFromPackageJSON) {
90
- return path.resolve(root, entryFromPackageJSON);
91
- }
92
- const possibleSourceFiles = await glob('{index,module,entry,input}.{ts,tsx,mjs,js,jsx}', {
93
- cwd: root,
94
- nodir: true,
95
- absolute: true
96
- });
97
- return possibleSourceFiles[0];
98
- }
99
-
100
- export { quiltModule };