@quilted/rollup 0.1.18 → 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 +25 -0
- package/build/esm/app.mjs +442 -233
- 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 +472 -109
- 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 -456
- 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 -429
- 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
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
const CSS_REGEX = /\.css$/;
|
|
2
|
-
const CSS_MODULE_REGEX = /\.module\.css$/;
|
|
3
|
-
function css({
|
|
4
|
-
minify = true,
|
|
5
|
-
emit = true
|
|
6
|
-
}) {
|
|
7
|
-
const styles = new Map();
|
|
8
|
-
return {
|
|
9
|
-
name: '@quilted/css',
|
|
10
|
-
async transform(code, id) {
|
|
11
|
-
if (!CSS_REGEX.test(id)) return;
|
|
12
|
-
const {
|
|
13
|
-
transform
|
|
14
|
-
} = await import('lightningcss');
|
|
15
|
-
const transformed = transform({
|
|
16
|
-
filename: id,
|
|
17
|
-
code: new TextEncoder().encode(code),
|
|
18
|
-
cssModules: CSS_MODULE_REGEX.test(id),
|
|
19
|
-
minify: emit && minify
|
|
20
|
-
});
|
|
21
|
-
styles.set(id, new TextDecoder().decode(transformed.code));
|
|
22
|
-
const exports = transformed.exports ? Object.fromEntries(Object.entries(transformed.exports).map(([key, exported]) => [key, exported.name])) : undefined;
|
|
23
|
-
return {
|
|
24
|
-
code: exports ? `export default JSON.parse(${JSON.stringify(JSON.stringify(exports))})` : `export default undefined;`,
|
|
25
|
-
map: {
|
|
26
|
-
mappings: ''
|
|
27
|
-
},
|
|
28
|
-
moduleSideEffects: 'no-treeshake'
|
|
29
|
-
};
|
|
30
|
-
},
|
|
31
|
-
async renderChunk(_, chunk) {
|
|
32
|
-
if (!emit) return null;
|
|
33
|
-
let chunkCss = '';
|
|
34
|
-
for (const id of Object.keys(chunk.modules)) {
|
|
35
|
-
if (CSS_REGEX.test(id) && styles.has(id)) {
|
|
36
|
-
chunkCss += styles.get(id);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
if (chunkCss.length === 0) return null;
|
|
40
|
-
const code = chunkCss;
|
|
41
|
-
|
|
42
|
-
// if (minify) {
|
|
43
|
-
// const {default: CleanCSS} = await import('clean-css');
|
|
44
|
-
|
|
45
|
-
// const cleaner = new CleanCSS({
|
|
46
|
-
// rebase: false,
|
|
47
|
-
// });
|
|
48
|
-
|
|
49
|
-
// const minified = cleaner.minify(chunkCss);
|
|
50
|
-
|
|
51
|
-
// if (minified.errors.length > 0) {
|
|
52
|
-
// throw minified.errors[0];
|
|
53
|
-
// }
|
|
54
|
-
|
|
55
|
-
// code = minified.styles;
|
|
56
|
-
// }
|
|
57
|
-
|
|
58
|
-
const fileHandle = this.emitFile({
|
|
59
|
-
type: 'asset',
|
|
60
|
-
name: `${chunk.fileName.split('.')[0]}.css`,
|
|
61
|
-
source: code
|
|
62
|
-
});
|
|
63
|
-
chunk.imports.push(this.getFileName(fileHandle));
|
|
64
|
-
return null;
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
export { css };
|
|
@@ -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 };
|