@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.
Files changed (126) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/build/esm/app.mjs +442 -233
  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 +13 -18
  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 +126 -27
  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/workers.d.ts +52 -0
  44. package/build/typescript/features/workers.d.ts.map +1 -0
  45. package/build/typescript/index.d.ts +3 -2
  46. package/build/typescript/index.d.ts.map +1 -1
  47. package/build/typescript/module.d.ts +24 -6
  48. package/build/typescript/module.d.ts.map +1 -1
  49. package/build/typescript/package.d.ts +196 -4
  50. package/build/typescript/package.d.ts.map +1 -1
  51. package/build/typescript/server.d.ts +98 -0
  52. package/build/typescript/server.d.ts.map +1 -0
  53. package/build/typescript/shared/browserslist.d.ts +20 -3
  54. package/build/typescript/shared/browserslist.d.ts.map +1 -1
  55. package/build/typescript/shared/path.d.ts +2 -0
  56. package/build/typescript/shared/path.d.ts.map +1 -0
  57. package/build/typescript/shared/rollup.d.ts +27 -1
  58. package/build/typescript/shared/rollup.d.ts.map +1 -1
  59. package/configuration/rollup.config.js +40 -0
  60. package/package.json +61 -8
  61. package/source/app.ts +472 -109
  62. package/source/features/assets.ts +5 -7
  63. package/source/features/async.ts +249 -0
  64. package/source/features/css.ts +4 -2
  65. package/source/features/env.ts +6 -0
  66. package/source/features/esnext.ts +70 -0
  67. package/source/features/graphql.ts +4 -2
  68. package/source/features/source-code.ts +26 -8
  69. package/source/features/workers.ts +292 -0
  70. package/source/index.ts +4 -0
  71. package/source/module.ts +45 -19
  72. package/source/package.ts +394 -36
  73. package/source/server.ts +245 -0
  74. package/source/shared/browserslist.ts +208 -18
  75. package/source/shared/path.ts +5 -0
  76. package/source/shared/rollup.ts +102 -4
  77. package/tsconfig.json +6 -2
  78. package/build/cjs/app.cjs +0 -456
  79. package/build/cjs/constants.cjs +0 -13
  80. package/build/cjs/features/assets.cjs +0 -240
  81. package/build/cjs/features/css.cjs +0 -71
  82. package/build/cjs/features/env.cjs +0 -135
  83. package/build/cjs/features/graphql/transform.cjs +0 -186
  84. package/build/cjs/features/graphql.cjs +0 -86
  85. package/build/cjs/features/request-router.cjs +0 -31
  86. package/build/cjs/features/source-code.cjs +0 -54
  87. package/build/cjs/features/system-js.cjs +0 -36
  88. package/build/cjs/features/typescript.cjs +0 -56
  89. package/build/cjs/index.cjs +0 -13
  90. package/build/cjs/module.cjs +0 -121
  91. package/build/cjs/package.cjs +0 -170
  92. package/build/cjs/shared/browserslist.cjs +0 -25
  93. package/build/cjs/shared/magic-module.cjs +0 -32
  94. package/build/cjs/shared/package-json.cjs +0 -31
  95. package/build/cjs/shared/rollup.cjs +0 -72
  96. package/build/cjs/shared/strings.cjs +0 -16
  97. package/build/esnext/app.esnext +0 -429
  98. package/build/esnext/constants.esnext +0 -7
  99. package/build/esnext/features/assets.esnext +0 -215
  100. package/build/esnext/features/css.esnext +0 -69
  101. package/build/esnext/features/env.esnext +0 -112
  102. package/build/esnext/features/graphql/transform.esnext +0 -181
  103. package/build/esnext/features/graphql.esnext +0 -84
  104. package/build/esnext/features/request-router.esnext +0 -29
  105. package/build/esnext/features/source-code.esnext +0 -51
  106. package/build/esnext/features/system-js.esnext +0 -33
  107. package/build/esnext/features/typescript.esnext +0 -34
  108. package/build/esnext/index.esnext +0 -3
  109. package/build/esnext/module.esnext +0 -100
  110. package/build/esnext/package.esnext +0 -148
  111. package/build/esnext/shared/browserslist.esnext +0 -23
  112. package/build/esnext/shared/magic-module.esnext +0 -30
  113. package/build/esnext/shared/package-json.esnext +0 -10
  114. package/build/esnext/shared/rollup.esnext +0 -49
  115. package/build/esnext/shared/strings.esnext +0 -14
  116. package/build/typescript/env.d.ts +0 -55
  117. package/build/typescript/env.d.ts.map +0 -1
  118. package/build/typescript/graphql/transform.d.ts +0 -17
  119. package/build/typescript/graphql/transform.d.ts.map +0 -1
  120. package/build/typescript/graphql.d.ts +0 -6
  121. package/build/typescript/graphql.d.ts.map +0 -1
  122. package/build/typescript/request-router.d.ts +0 -15
  123. package/build/typescript/request-router.d.ts.map +0 -1
  124. package/build/typescript/shared/source-code.d.ts +0 -5
  125. package/build/typescript/shared/source-code.d.ts.map +0 -1
  126. package/quilt.project.ts +0 -5
@@ -1,23 +1,148 @@
1
- async function getBrowserTargetDetails(targetSelection = {}, {
2
- root
3
- } = {}) {
1
+ async function getBrowserGroupTargetDetails(targetSelection = {}, { root } = {}) {
2
+ const { default: browserslist } = await import('browserslist');
4
3
  const targets = Array.isArray(targetSelection) ? {
5
4
  browsers: targetSelection
6
5
  } : targetSelection;
7
- const targetBrowsers = targets.browsers ?? (await (async () => {
8
- const {
9
- default: browserslist
10
- } = await import('browserslist');
11
- const config = browserslist.findConfig(root);
12
- if (config == null) return ['defaults'];
13
- const targetName = targets.name ?? 'defaults';
14
- return config[targetName] ?? ['defaults'];
15
- })());
16
- const name = targets.name === 'defaults' ? 'default' : targets.name;
17
- return {
6
+ const targetBrowsers = targets.browsers ?? await (async () => {
7
+ const config = await getBrowserGroups({ root });
8
+ const targetName = targets.name ?? "default";
9
+ return config[targetName] ?? ["defaults"];
10
+ })();
11
+ return { name: targets.name, browsers: browserslist(targetBrowsers) };
12
+ }
13
+ async function getBrowserGroups({
14
+ root = process.cwd()
15
+ } = {}) {
16
+ const { default: browserslist } = await import('browserslist');
17
+ const config = browserslist.findConfig(root);
18
+ if (config == null)
19
+ return { default: browserslist(["defaults"]) };
20
+ const { defaults, ...rest } = config;
21
+ const browserGroups = {};
22
+ const groupsWithFullList = Object.entries(rest).map(([name, browsers]) => ({
23
+ name,
24
+ browsers: browserslist(browsers)
25
+ })).sort((first, second) => first.browsers.length - second.browsers.length);
26
+ for (const { name, browsers } of groupsWithFullList) {
27
+ browserGroups[name] = browsers;
28
+ }
29
+ browserGroups.default = defaults;
30
+ return browserGroups;
31
+ }
32
+ async function getBrowserGroupRegularExpressions(groups) {
33
+ const [{ default: browserslist }, { getUserAgentRegex }] = await Promise.all([
34
+ import('browserslist'),
35
+ import('browserslist-useragent-regexp')
36
+ ]);
37
+ const groupsWithFullList = Object.entries(
38
+ groups ?? await getBrowserGroups()
39
+ ).map(([name, browsers]) => ({
18
40
  name,
19
- browsers: targetBrowsers
41
+ browsers: browserslist(browsers)
42
+ })).sort((first, second) => first.browsers.length - second.browsers.length);
43
+ if (groupsWithFullList.length === 0)
44
+ return {};
45
+ const lastGroup = groupsWithFullList.pop();
46
+ const regexes = {};
47
+ for (const { name, browsers } of groupsWithFullList) {
48
+ const regex = getUserAgentRegex({
49
+ browsers,
50
+ ignoreMinor: true,
51
+ ignorePatch: true,
52
+ allowHigherVersions: true
53
+ });
54
+ regexes[name] = regex;
55
+ }
56
+ regexes[lastGroup.name] = new RegExp("");
57
+ return regexes;
58
+ }
59
+ let esmBrowserslist;
60
+ async function targetsSupportModules(targets) {
61
+ esmBrowserslist ??= (async () => {
62
+ const { default: browserslist } = await import('browserslist');
63
+ return new Set(
64
+ browserslist(
65
+ "defaults and fully supports es6-module and fully supports es6-module-dynamic-import"
66
+ )
67
+ );
68
+ })();
69
+ const esmBrowsers = await esmBrowserslist;
70
+ return targets.every((target) => esmBrowsers.has(target));
71
+ }
72
+ const BROWSESLIST_BROWSER_TO_MDN_BROWSER = /* @__PURE__ */ new Map([
73
+ ["and_chr", "chrome_android"],
74
+ ["and_ff", "firefox_android"],
75
+ ["and_qq", "qq_android"],
76
+ ["and_uc", "uc_android"],
77
+ ["android", "webview_android"],
78
+ ["chrome", "chrome"],
79
+ ["edge", "edge"],
80
+ ["edge_mob", "edge_mobile"],
81
+ ["firefox", "firefox"],
82
+ ["ie", "ie"],
83
+ ["ios_saf", "safari_ios"],
84
+ ["node", "nodejs"],
85
+ ["opera", "opera"],
86
+ ["safari", "safari"],
87
+ ["samsung", "samsunginternet_android"]
88
+ ]);
89
+ async function rollupGenerateOptionsForBrowsers(browsers) {
90
+ const [{ default: semver }, { default: mdn }] = await Promise.all([
91
+ import('semver'),
92
+ import('@mdn/browser-compat-data', { assert: { type: 'json' } })
93
+ ]);
94
+ const arrowFunctionsSupport = mdn.javascript.functions.arrow_functions.__compat.support;
95
+ const constBindingsSupport = mdn.javascript.statements.const.__compat.support;
96
+ const objectShorthandSupport = mdn.javascript.grammar.shorthand_object_literals.__compat.support;
97
+ const symbolsSupport = mdn.javascript.builtins.Symbol.__compat.support;
98
+ let arrowFunctions = true;
99
+ let constBindings = true;
100
+ let objectShorthand = true;
101
+ let symbols = true;
102
+ const isSupported = (browser, version, supportList) => {
103
+ const supportedVersionDetails = supportList[browser];
104
+ if (supportedVersionDetails == null)
105
+ return false;
106
+ const supportedVersion = semver.coerce(
107
+ supportedVersionDetails.version_added
108
+ );
109
+ if (supportedVersion == null)
110
+ return false;
111
+ return semver.gte(version, supportedVersion);
112
+ };
113
+ for (const browser of browsers) {
114
+ const [name, version] = browser.split(" ");
115
+ const semverVersion = semver.coerce(version);
116
+ if (semverVersion == null)
117
+ continue;
118
+ const mdnBrowser = BROWSESLIST_BROWSER_TO_MDN_BROWSER.get(name);
119
+ if (mdnBrowser == null)
120
+ continue;
121
+ arrowFunctions &&= isSupported(
122
+ mdnBrowser,
123
+ semverVersion,
124
+ arrowFunctionsSupport
125
+ );
126
+ constBindings &&= isSupported(
127
+ mdnBrowser,
128
+ semverVersion,
129
+ constBindingsSupport
130
+ );
131
+ objectShorthand &&= isSupported(
132
+ mdnBrowser,
133
+ semverVersion,
134
+ objectShorthandSupport
135
+ );
136
+ symbols &&= isSupported(mdnBrowser, semverVersion, symbolsSupport);
137
+ }
138
+ return {
139
+ preset: "es2015",
140
+ arrowFunctions,
141
+ constBindings,
142
+ objectShorthand,
143
+ reservedNamesAsProps: objectShorthand,
144
+ symbols
20
145
  };
21
146
  }
22
147
 
23
- export { getBrowserTargetDetails };
148
+ export { getBrowserGroupRegularExpressions, getBrowserGroupTargetDetails, getBrowserGroups, rollupGenerateOptionsForBrowsers, targetsSupportModules };
@@ -1,5 +1,5 @@
1
- const VIRTUAL_MODULE_PREFIX = '\0';
2
- const VIRTUAL_MODULE_POSTFIX = '/module.js';
1
+ const VIRTUAL_MODULE_PREFIX = "\0";
2
+ const VIRTUAL_MODULE_POSTFIX = "/module.js";
3
3
  function createMagicModulePlugin({
4
4
  name,
5
5
  module,
@@ -10,20 +10,22 @@ function createMagicModulePlugin({
10
10
  return {
11
11
  name,
12
12
  resolveId(id) {
13
- if (id !== module) return null;
13
+ if (id !== module)
14
+ return null;
14
15
  return {
15
16
  id: alias,
16
- moduleSideEffects: sideEffects ? 'no-treeshake' : undefined
17
+ moduleSideEffects: sideEffects ? "no-treeshake" : void 0
17
18
  };
18
19
  },
19
20
  load: getSource ? async function load(source) {
20
- if (source !== alias) return null;
21
+ if (source !== alias)
22
+ return null;
21
23
  const code = await getSource.call(this);
22
24
  return {
23
25
  code,
24
- moduleSideEffects: sideEffects ? 'no-treeshake' : undefined
26
+ moduleSideEffects: sideEffects ? "no-treeshake" : void 0
25
27
  };
26
- } : undefined
28
+ } : void 0
27
29
  };
28
30
  }
29
31
 
@@ -3,7 +3,13 @@ import { fileURLToPath } from 'node:url';
3
3
  import { readFile } from 'node:fs/promises';
4
4
 
5
5
  async function loadPackageJSON(root) {
6
- const file = await readFile(path.join(typeof root === 'string' ? root : fileURLToPath(root), 'package.json'), 'utf8');
6
+ const file = await readFile(
7
+ path.join(
8
+ typeof root === "string" ? root : fileURLToPath(root),
9
+ "package.json"
10
+ ),
11
+ "utf8"
12
+ );
7
13
  return JSON.parse(file);
8
14
  }
9
15
 
@@ -0,0 +1,7 @@
1
+ import { fileURLToPath } from 'node:url';
2
+
3
+ function resolveRoot(root) {
4
+ return typeof root === "string" ? root : fileURLToPath(root);
5
+ }
6
+
7
+ export { resolveRoot };
@@ -5,45 +5,109 @@ import replace from '@rollup/plugin-replace';
5
5
  function smartReplace(values, options) {
6
6
  return replace({
7
7
  // @see https://github.com/vitejs/vite/blob/2b1ffe86328f9d06ef9528ee117b61889893ddcc/packages/vite/src/node/plugins/define.ts#L108-L119
8
- delimiters: ['(?<![\\p{L}\\p{N}_$]|(?<!\\.\\.)\\.)(', ')(?:(?<=\\.)|(?![\\p{L}\\p{N}_$]|\\s*?=[^=]))'],
8
+ delimiters: [
9
+ "(?<![\\p{L}\\p{N}_$]|(?<!\\.\\.)\\.)(",
10
+ ")(?:(?<=\\.)|(?![\\p{L}\\p{N}_$]|\\s*?=[^=]))"
11
+ ],
9
12
  preventAssignment: true,
10
13
  ...options,
11
14
  values
12
15
  });
13
16
  }
14
- function removeBuildFiles(patterns, {
15
- root = process.cwd()
16
- } = {}) {
17
+ function removeBuildFiles(patterns, { root = process.cwd() } = {}) {
17
18
  return {
18
- name: '@quilt/remove-build-files',
19
+ name: "@quilt/remove-build-files",
19
20
  async buildStart() {
20
21
  const matches = await glob(patterns, {
21
22
  cwd: root,
22
23
  absolute: true
23
24
  });
24
- await Promise.all(matches.map(file => fs.rm(file, {
25
- recursive: true,
26
- force: true
27
- })));
25
+ await Promise.all(
26
+ matches.map((file) => fs.rm(file, { recursive: true, force: true }))
27
+ );
28
28
  }
29
29
  };
30
30
  }
31
- async function getNodePlugins() {
32
- const [{
33
- default: commonjs
34
- }, {
35
- default: json
36
- }, {
37
- default: nodeResolve
38
- }, {
39
- default: nodeExternals
40
- }] = await Promise.all([import('@rollup/plugin-commonjs'), import('@rollup/plugin-json'), import('@rollup/plugin-node-resolve'), import('rollup-plugin-node-externals')]);
41
- return [nodeExternals({}), nodeResolve({
42
- preferBuiltins: true,
43
- dedupe: []
44
- // extensions,
45
- // exportConditions,
46
- }), commonjs(), json()];
31
+ async function getNodePlugins({
32
+ bundle = {}
33
+ } = {}) {
34
+ const [
35
+ { default: commonjs },
36
+ { default: json },
37
+ { default: nodeResolve },
38
+ { default: nodeExternals }
39
+ ] = await Promise.all([
40
+ import('@rollup/plugin-commonjs'),
41
+ import('@rollup/plugin-json'),
42
+ import('@rollup/plugin-node-resolve'),
43
+ import('rollup-plugin-node-externals')
44
+ ]);
45
+ let nodeExternalsOptions;
46
+ if (bundle === true) {
47
+ nodeExternalsOptions = {
48
+ builtins: true,
49
+ builtinsPrefix: "strip",
50
+ deps: false,
51
+ devDeps: false,
52
+ peerDeps: false,
53
+ optDeps: false
54
+ };
55
+ } else if (bundle === false) {
56
+ nodeExternalsOptions = {
57
+ builtins: true,
58
+ builtinsPrefix: "add",
59
+ deps: true,
60
+ devDeps: true,
61
+ peerDeps: true,
62
+ optDeps: true
63
+ };
64
+ } else {
65
+ const {
66
+ builtins: bundleBuiltins = false,
67
+ dependencies: bundleDependencies = false,
68
+ devDependencies: bundleDevDependencies = true,
69
+ peerDependencies: bundlePeerDependencies = false,
70
+ include: alwaysBundleDependencies,
71
+ exclude: neverBundleDependencies
72
+ } = bundle;
73
+ nodeExternalsOptions = {
74
+ builtins: !bundleBuiltins,
75
+ builtinsPrefix: bundleBuiltins ? "strip" : "add",
76
+ deps: !bundleDependencies,
77
+ devDeps: !bundleDevDependencies,
78
+ peerDeps: !bundlePeerDependencies,
79
+ optDeps: !bundlePeerDependencies,
80
+ include: neverBundleDependencies,
81
+ exclude: alwaysBundleDependencies
82
+ };
83
+ }
84
+ return [
85
+ nodeExternals(nodeExternalsOptions),
86
+ nodeResolve({
87
+ preferBuiltins: true,
88
+ dedupe: [],
89
+ extensions: [
90
+ ".ts",
91
+ ".tsx",
92
+ ".mts",
93
+ ".mtsx",
94
+ ".js",
95
+ ".jsx",
96
+ ".es6",
97
+ ".es",
98
+ ".mjs"
99
+ ],
100
+ exportConditions: [
101
+ "esnext",
102
+ "quilt:esnext",
103
+ "default",
104
+ "module",
105
+ "import"
106
+ ]
107
+ }),
108
+ commonjs(),
109
+ json()
110
+ ];
47
111
  }
48
112
 
49
113
  export { getNodePlugins, removeBuildFiles, smartReplace };
@@ -1,12 +1,13 @@
1
1
  function multiline(strings, ...values) {
2
- let result = strings.reduce((combined, string, index) => `${combined}${string}${values[index] ?? ''}`, '');
3
-
4
- // Inspired by https://github.com/zspecza/common-tags/blob/master/src/stripIndentTransformer/stripIndentTransformer.js#L8
2
+ let result = strings.reduce(
3
+ (combined, string, index) => `${combined}${string}${values[index] ?? ""}`,
4
+ ""
5
+ );
5
6
  const match = result.match(/^[^\S\n]*(?=\S)/gm);
6
- const indent = match && Math.min(...match.map(indent => indent.length));
7
+ const indent = match && Math.min(...match.map((indent2) => indent2.length));
7
8
  if (indent) {
8
- const regexp = new RegExp(`^.{${indent}}`, 'gm');
9
- result = result.replace(regexp, '');
9
+ const regexp = new RegExp(`^.{${indent}}`, "gm");
10
+ result = result.replace(regexp, "");
10
11
  }
11
12
  return result.trim();
12
13
  }