@quilted/rollup 0.2.24 → 0.2.26

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 CHANGED
@@ -1,5 +1,17 @@
1
1
  # @quilted/rollup
2
2
 
3
+ ## 0.2.26
4
+
5
+ ### Patch Changes
6
+
7
+ - [`473928a`](https://github.com/lemonmade/quilt/commit/473928a44115f8c27521d66cfe68cc5e213c5a54) Thanks [@lemonmade](https://github.com/lemonmade)! - Update development dependencies
8
+
9
+ ## 0.2.25
10
+
11
+ ### Patch Changes
12
+
13
+ - [`2a59a4c`](https://github.com/lemonmade/quilt/commit/2a59a4c89141c42853f7afa5c3497eae97982a5b) Thanks [@lemonmade](https://github.com/lemonmade)! - Fix server resolution for async components
14
+
3
15
  ## 0.2.24
4
16
 
5
17
  ### Patch Changes
package/build/esm/app.mjs CHANGED
@@ -534,7 +534,7 @@ function magicModuleAppRequestRouter({
534
534
  return multiline`
535
535
  import '@quilted/quilt/globals';
536
536
 
537
- import {jsx} from 'react/jsx-runtime';
537
+ import {jsx} from 'preact/jsx-runtime';
538
538
  import {RequestRouter} from '@quilted/quilt/request-router';
539
539
  import {renderToResponse} from '@quilted/quilt/server';
540
540
 
@@ -570,18 +570,18 @@ function magicModuleAppBrowserEntry({
570
570
  module: MAGIC_MODULE_ENTRY,
571
571
  sideEffects: true,
572
572
  async source() {
573
- const reactRootFunction = hydrate ? "hydrateRoot" : "createRoot";
573
+ const reactRootFunction = hydrate ? "hydrate" : "render";
574
574
  return multiline`
575
575
  import '@quilted/quilt/globals';
576
576
 
577
- import {jsx} from 'react/jsx-runtime';
578
- import {${reactRootFunction}} from 'react-dom/client';
577
+ import {jsx} from 'preact/jsx-runtime';
578
+ import {${reactRootFunction}} from 'preact';
579
579
 
580
580
  import App from ${JSON.stringify(MAGIC_MODULE_APP_COMPONENT)};
581
581
 
582
582
  const element = document.querySelector(${JSON.stringify(selector)});
583
583
 
584
- ${hydrate ? `${reactRootFunction}(element, jsx(App));` : `${reactRootFunction}(element).render(jsx(App));`}
584
+ ${reactRootFunction}(jsx(App), element);
585
585
  `;
586
586
  }
587
587
  });
@@ -732,8 +732,7 @@ function createManualChunksSorter() {
732
732
  let relativeId;
733
733
  if (id.includes("/node_modules/")) {
734
734
  const moduleInfo = getModuleInfo(id);
735
- if (moduleInfo == null)
736
- return;
735
+ if (moduleInfo == null) return;
737
736
  if (moduleInfo.importers.length > 0 && moduleInfo.importers.every(
738
737
  (importer) => importer.includes("/node_modules/")
739
738
  )) {
@@ -22,8 +22,7 @@ async function writeManifestForBundle(bundle, { file, baseURL, cacheKey, priorit
22
22
  const entryChunk = entries[0];
23
23
  const dependencyMap = /* @__PURE__ */ new Map();
24
24
  for (const output of outputs) {
25
- if (output.type !== "chunk")
26
- continue;
25
+ if (output.type !== "chunk") continue;
27
26
  dependencyMap.set(output.fileName, output.imports);
28
27
  }
29
28
  const assets = [];
@@ -51,14 +50,11 @@ async function writeManifestForBundle(bundle, { file, baseURL, cacheKey, priorit
51
50
  modules: {}
52
51
  };
53
52
  for (const output of outputs) {
54
- if (output.type !== "chunk")
55
- continue;
53
+ if (output.type !== "chunk") continue;
56
54
  const originalModuleId = output.facadeModuleId ?? output.moduleIds[output.moduleIds.length - 1];
57
- if (originalModuleId == null)
58
- continue;
55
+ if (originalModuleId == null) continue;
59
56
  const moduleId = this.getModuleInfo(originalModuleId)?.meta.quilt?.moduleID;
60
- if (moduleId == null)
61
- continue;
57
+ if (moduleId == null) continue;
62
58
  manifest.modules[moduleId] = createAssetsEntry(
63
59
  [...output.imports, output.fileName],
64
60
  { dependencyMap, getAssetId }
@@ -75,8 +71,7 @@ function createAssetsEntry(files, {
75
71
  const scripts = [];
76
72
  const allFiles = /* @__PURE__ */ new Set();
77
73
  const addFile = (file) => {
78
- if (allFiles.has(file))
79
- return;
74
+ if (allFiles.has(file)) return;
80
75
  allFiles.add(file);
81
76
  for (const dependency of dependencyMap.get(file) ?? []) {
82
77
  addFile(dependency);
@@ -13,17 +13,20 @@ function asyncModules({
13
13
  return {
14
14
  name: "@quilted/async",
15
15
  async resolveId(id, importer) {
16
- if (id.startsWith(IMPORT_PREFIX))
17
- return `\0${id}`;
18
- if (!id.startsWith(MODULE_PREFIX))
16
+ let prefix;
17
+ if (id.startsWith(IMPORT_PREFIX)) {
18
+ prefix = IMPORT_PREFIX;
19
+ } else if (id.startsWith(MODULE_PREFIX)) {
20
+ prefix = MODULE_PREFIX;
21
+ } else {
19
22
  return null;
20
- const imported = id.replace(MODULE_PREFIX, "");
23
+ }
24
+ const imported = id.replace(prefix, "");
21
25
  const resolved = await this.resolve(imported, importer, {
22
26
  skipSelf: true
23
27
  });
24
- if (resolved == null)
25
- return null;
26
- return `\0${MODULE_PREFIX}${resolved.id}`;
28
+ if (resolved == null) return null;
29
+ return `\0${prefix}${resolved.id}`;
27
30
  },
28
31
  resolveDynamicImport(specifier) {
29
32
  if (typeof specifier === "string" && specifier.startsWith(IMPORT_PREFIX)) {
@@ -88,25 +91,21 @@ function defaultModuleID({ imported }) {
88
91
  async function preloadAsyncAssetsInESMBundle(bundle) {
89
92
  const { parse: parseImports } = await import('es-module-lexer');
90
93
  for (const chunk of Object.values(bundle)) {
91
- if (chunk.type !== "chunk")
92
- continue;
93
- if (chunk.dynamicImports.length === 0)
94
- continue;
94
+ if (chunk.type !== "chunk") continue;
95
+ if (chunk.dynamicImports.length === 0) continue;
95
96
  const { code } = chunk;
96
97
  const newCode = new MagicString(code);
97
98
  const imports = (await parseImports(code))[0];
98
99
  for (const imported of imports) {
99
100
  const { s: start, e: end, ss: importStart, d: dynamicStart } = imported;
100
- if (dynamicStart < 0)
101
- continue;
101
+ if (dynamicStart < 0) continue;
102
102
  const importSource = code.slice(start + 1, end - 1);
103
103
  const dependencies = getDependenciesForImport(
104
104
  importSource,
105
105
  chunk,
106
106
  bundle
107
107
  );
108
- if (dependencies.size === 1)
109
- continue;
108
+ if (dependencies.size === 1) continue;
110
109
  const originalImport = code.slice(importStart, end + 1);
111
110
  newCode.overwrite(
112
111
  importStart,
@@ -119,10 +118,8 @@ async function preloadAsyncAssetsInESMBundle(bundle) {
119
118
  }
120
119
  async function preloadAsyncAssetsInSystemJSBundle(bundle) {
121
120
  for (const chunk of Object.values(bundle)) {
122
- if (chunk.type !== "chunk")
123
- continue;
124
- if (chunk.dynamicImports.length === 0)
125
- continue;
121
+ if (chunk.type !== "chunk") continue;
122
+ if (chunk.dynamicImports.length === 0) continue;
126
123
  const { code } = chunk;
127
124
  const newCode = new MagicString(code);
128
125
  const systemDynamicImportRegex = /\bmodule\.import\(([^)]*)\)/g;
@@ -135,8 +132,7 @@ async function preloadAsyncAssetsInSystemJSBundle(bundle) {
135
132
  chunk,
136
133
  bundle
137
134
  );
138
- if (dependencies.size === 1)
139
- continue;
135
+ if (dependencies.size === 1) continue;
140
136
  newCode.overwrite(
141
137
  match.index,
142
138
  match.index + originalImport.length,
@@ -157,17 +153,13 @@ function getDependenciesForImport(imported, chunk, bundle) {
157
153
  const analyzed = /* @__PURE__ */ new Set();
158
154
  const normalizedFile = posix.join(posix.dirname(originalFilename), imported);
159
155
  const addDependencies = (filename) => {
160
- if (filename === originalFilename)
161
- return;
162
- if (analyzed.has(filename))
163
- return;
156
+ if (filename === originalFilename) return;
157
+ if (analyzed.has(filename)) return;
164
158
  analyzed.add(filename);
165
159
  const chunk2 = bundle[filename];
166
- if (chunk2 == null)
167
- return;
160
+ if (chunk2 == null) return;
168
161
  dependencies.add(chunk2.fileName);
169
- if (chunk2.type !== "chunk")
170
- return;
162
+ if (chunk2.type !== "chunk") return;
171
163
  for (const imported2 of chunk2.imports) {
172
164
  addDependencies(imported2);
173
165
  }
@@ -5,8 +5,7 @@ function css({ minify = true, emit = true, targets }) {
5
5
  return {
6
6
  name: "@quilted/css",
7
7
  async transform(code, id) {
8
- if (!CSS_REGEX.test(id))
9
- return;
8
+ if (!CSS_REGEX.test(id)) return;
10
9
  const { transform, browserslistToTargets } = await import('lightningcss');
11
10
  const transformed = transform({
12
11
  filename: id,
@@ -31,16 +30,14 @@ function css({ minify = true, emit = true, targets }) {
31
30
  };
32
31
  },
33
32
  async renderChunk(_, chunk) {
34
- if (!emit)
35
- return null;
33
+ if (!emit) return null;
36
34
  let chunkCss = "";
37
35
  for (const id of Object.keys(chunk.modules)) {
38
36
  if (CSS_REGEX.test(id) && styles.has(id)) {
39
37
  chunkCss += styles.get(id);
40
38
  }
41
39
  }
42
- if (chunkCss.length === 0)
43
- return null;
40
+ if (chunkCss.length === 0) return null;
44
41
  const code = chunkCss;
45
42
  const fileHandle = this.emitFile({
46
43
  type: "asset",
@@ -41,11 +41,9 @@ function magicModuleEnv({
41
41
  }
42
42
  const loadedEnv = await loadEnv.call(this, { mode, dotenv });
43
43
  for (const inlineVariable of inline.sort()) {
44
- if (inlineVariable in inlineEnv)
45
- continue;
44
+ if (inlineVariable in inlineEnv) continue;
46
45
  const value = process.env[inlineVariable] ?? loadedEnv[inlineVariable];
47
- if (value == null)
48
- continue;
46
+ if (value == null) continue;
49
47
  inlineEnv[inlineVariable] = typeof value === "string" && value[0] === '"' && value[value.length - 1] === '"' ? JSON.parse(value) : value;
50
48
  }
51
49
  return multiline`
@@ -107,8 +105,7 @@ async function loadEnv({ root, mode, dotenv }) {
107
105
  })
108
106
  );
109
107
  for (const envFileResult of envFileResults) {
110
- if (envFileResult == null)
111
- continue;
108
+ if (envFileResult == null) continue;
112
109
  Object.assign(env, envFileResult);
113
110
  }
114
111
  }
@@ -121,8 +118,7 @@ function findWorkspaceRoot(start = process.cwd()) {
121
118
  return current;
122
119
  }
123
120
  const next = path.dirname(current);
124
- if (next === current)
125
- return void 0;
121
+ if (next === current) return void 0;
126
122
  current = next;
127
123
  }
128
124
  }
@@ -9,16 +9,14 @@ function graphql({ manifest } = {}) {
9
9
  return {
10
10
  name: "@quilted/graphql",
11
11
  async transform(code, id) {
12
- if (!id.endsWith(".graphql") && !id.endsWith(".gql"))
13
- return null;
12
+ if (!id.endsWith(".graphql") && !id.endsWith(".gql")) return null;
14
13
  const topLevelDefinitions = /* @__PURE__ */ new Set();
15
14
  const loadedDocument = await loadDocument(
16
15
  code,
17
16
  id,
18
17
  this,
19
18
  (document2, level) => {
20
- if (level !== 0)
21
- return;
19
+ if (level !== 0) return;
22
20
  for (const definition of document2.definitions) {
23
21
  if ("name" in definition && definition.name != null) {
24
22
  topLevelDefinitions.add(definition.name.value);
@@ -41,8 +39,7 @@ function graphql({ manifest } = {}) {
41
39
  };
42
40
  },
43
41
  async generateBundle() {
44
- if (!shouldWriteManifest)
45
- return;
42
+ if (!shouldWriteManifest) return;
46
43
  const operations = {};
47
44
  for (const moduleId of this.getModuleIds()) {
48
45
  const operation = this.getModuleInfo(moduleId)?.meta?.quilt?.graphql;
@@ -50,8 +47,7 @@ function graphql({ manifest } = {}) {
50
47
  operations[operation.id] = operation.source;
51
48
  }
52
49
  }
53
- if (Object.keys(operations).length === 0)
54
- return;
50
+ if (Object.keys(operations).length === 0) return;
55
51
  await mkdir(dirname(manifestPath), { recursive: true });
56
52
  await writeFile(manifestPath, JSON.stringify(operations, null, 2));
57
53
  }
@@ -66,8 +62,7 @@ async function loadDocument(code, file, plugin, add, level = 0, seen = /* @__PUR
66
62
  }
67
63
  const resolvedImports = await Promise.all(
68
64
  imports.map(async (imported) => {
69
- if (seen.has(imported))
70
- return;
65
+ if (seen.has(imported)) return;
71
66
  seen.add(imported);
72
67
  const resolvedId = await plugin.resolve(imported, file);
73
68
  if (resolvedId == null) {
@@ -92,8 +87,7 @@ async function loadDocument(code, file, plugin, add, level = 0, seen = /* @__PUR
92
87
  })
93
88
  );
94
89
  for (const importedDocument of resolvedImports) {
95
- if (importedDocument == null)
96
- continue;
90
+ if (importedDocument == null) continue;
97
91
  document.definitions.push(...importedDocument.definitions);
98
92
  }
99
93
  return document;
@@ -10,8 +10,7 @@ async function monorepoPackageAliases({
10
10
  function processProject(project2) {
11
11
  const { dependencies, devDependencies } = project2.packageJSON.raw;
12
12
  for (const pkg of Object.keys({ ...dependencies, ...devDependencies })) {
13
- if (seenDependencies.has(pkg))
14
- continue;
13
+ if (seenDependencies.has(pkg)) continue;
15
14
  seenDependencies.add(pkg);
16
15
  let packageRoot;
17
16
  try {
@@ -22,8 +21,7 @@ async function monorepoPackageAliases({
22
21
  continue;
23
22
  }
24
23
  const packageProject = Project.load(packageRoot);
25
- if (seenProjects.has(packageProject))
26
- continue;
24
+ if (seenProjects.has(packageProject)) continue;
27
25
  seenProjects.add(packageProject);
28
26
  processProject(packageProject);
29
27
  }
@@ -14,7 +14,7 @@ function sourceCode({
14
14
  // Support very modern features
15
15
  target: "es2022",
16
16
  jsx: "automatic",
17
- jsxImportSource: typeof react === "string" ? react : "react",
17
+ jsxImportSource: typeof react === "string" ? react : "preact",
18
18
  exclude: "node_modules/**"
19
19
  });
20
20
  }
@@ -30,7 +30,7 @@ function sourceCode({
30
30
  require.resolve("@babel/preset-react"),
31
31
  {
32
32
  runtime: "automatic",
33
- importSource: typeof react === "string" ? react : "react",
33
+ importSource: typeof react === "string" ? react : "preact",
34
34
  development: mode === "development"
35
35
  }
36
36
  ],
@@ -7,8 +7,7 @@ function systemJS({ minify = false } = {}) {
7
7
  return {
8
8
  name: "@quilted/system-js",
9
9
  async renderChunk(code, chunk, options) {
10
- if (options.format !== "system" || !chunk.isEntry)
11
- return null;
10
+ if (options.format !== "system" || !chunk.isEntry) return null;
12
11
  const require = createRequire(import.meta.url);
13
12
  const systemjs = minify ? require.resolve("systemjs/dist/s.min.js") : require.resolve("systemjs/dist/s.js");
14
13
  const fileHandle = this.emitFile({
@@ -9,8 +9,7 @@ async function tsconfigAliases({
9
9
  getTSConfig(root)
10
10
  ]);
11
11
  const tsconfigPaths = tsconfig?.compilerOptions?.paths;
12
- if (tsconfigPaths == null)
13
- return void 0;
12
+ if (tsconfigPaths == null) return void 0;
14
13
  return alias({
15
14
  entries: Object.entries(tsconfigPaths).map(([name, aliases]) => {
16
15
  return {
@@ -23,19 +23,16 @@ function workers({
23
23
  },
24
24
  async resolveId(source, importer) {
25
25
  const context = parseWorkerImport(source);
26
- if (context == null)
27
- return null;
26
+ if (context == null) return null;
28
27
  const resolvedModule = await this.resolve(context.module, importer, {
29
28
  skipSelf: true
30
29
  });
31
- if (resolvedModule == null)
32
- return null;
30
+ if (resolvedModule == null) return null;
33
31
  return serializeWorkerImport({ ...context, module: resolvedModule.id });
34
32
  },
35
33
  async load(id) {
36
34
  const context = parseWorkerImport(id);
37
- if (context == null)
38
- return null;
35
+ if (context == null) return null;
39
36
  const { module } = context;
40
37
  const workerPlugins = [
41
38
  workerMagicModules(),
@@ -98,11 +95,9 @@ function workers({
98
95
  })};`;
99
96
  },
100
97
  generateBundle(_, bundle) {
101
- if (write)
102
- return;
98
+ if (write) return;
103
99
  for (const chunk of workerMap.values()) {
104
- if (chunk.fileName in bundle)
105
- continue;
100
+ if (chunk.fileName in bundle) continue;
106
101
  bundle[chunk.fileName] = chunk;
107
102
  }
108
103
  }
@@ -119,15 +114,13 @@ function workerMagicModules() {
119
114
  },
120
115
  async load(id) {
121
116
  const context = parseWorkerImport(id, ENTRY_PREFIX);
122
- if (context == null)
123
- return null;
117
+ if (context == null) return null;
124
118
  return contentForWorker(context);
125
119
  }
126
120
  };
127
121
  }
128
122
  function parseWorkerImport(id, prefix = PREFIX) {
129
- if (!id.startsWith(prefix))
130
- return void 0;
123
+ if (!id.startsWith(prefix)) return void 0;
131
124
  const [module, searchString] = id.slice(prefix.length).split("?");
132
125
  const searchParams = new URLSearchParams(searchString);
133
126
  const wrapperModule = searchParams.get("module");
@@ -154,7 +147,7 @@ const workerFunctionContent = (pkg) => /* @__PURE__ */ new Map([
154
147
  ]);
155
148
  const KNOWN_WRAPPER_MODULES = /* @__PURE__ */ new Map([
156
149
  ["@quilted/workers", workerFunctionContent("@quilted/workers")],
157
- ["@quilted/react-workers", workerFunctionContent("@quilted/react-workers")],
150
+ ["@quilted/preact-workers", workerFunctionContent("@quilted/preact-workers")],
158
151
  ["@quilted/quilt/threads", workerFunctionContent("@quilted/quilt/threads")]
159
152
  ]);
160
153
  function contentForWorker({ module, wrapper }) {
@@ -284,8 +284,7 @@ function sourceForEntries(entries, { root }) {
284
284
  let sourceRoot = root;
285
285
  const sourceEntryFiles = Object.values(entries);
286
286
  for (const entry of sourceEntryFiles) {
287
- if (!entry.startsWith(root))
288
- continue;
287
+ if (!entry.startsWith(root)) continue;
289
288
  sourceRoot = path.resolve(
290
289
  root,
291
290
  path.relative(root, entry).split(path.sep)[0] ?? "."
@@ -16,8 +16,7 @@ async function getBrowserGroups({
16
16
  } = {}) {
17
17
  const { default: browserslist } = await import('browserslist');
18
18
  const config = browserslist.findConfig(root);
19
- if (config == null)
20
- return { default: browserslist(["defaults"]) };
19
+ if (config == null) return { default: browserslist(["defaults"]) };
21
20
  const { defaults, ...rest } = config;
22
21
  const browserGroups = {};
23
22
  const groupsWithFullList = Object.entries(rest).map(([name, browsers]) => ({
@@ -41,8 +40,7 @@ async function getBrowserGroupRegularExpressions(groups) {
41
40
  name,
42
41
  browsers: browserslist(browsers)
43
42
  })).sort((first, second) => first.browsers.length - second.browsers.length);
44
- if (groupsWithFullList.length === 0)
45
- return {};
43
+ if (groupsWithFullList.length === 0) return {};
46
44
  const lastGroup = groupsWithFullList.pop();
47
45
  const regexes = {};
48
46
  for (const { name, browsers } of groupsWithFullList) {
@@ -135,21 +133,17 @@ function* mdnBrowserVersions(browsers, semver) {
135
133
  for (const browser of browsers) {
136
134
  const [name, version] = browser.split(" ");
137
135
  const mdnBrowser = BROWSESLIST_BROWSER_TO_MDN_BROWSER.get(name);
138
- if (mdnBrowser == null)
139
- continue;
136
+ if (mdnBrowser == null) continue;
140
137
  const semverVersion = semver.coerce(version);
141
- if (semverVersion == null)
142
- continue;
138
+ if (semverVersion == null) continue;
143
139
  yield { name: mdnBrowser, version: semverVersion };
144
140
  }
145
141
  }
146
142
  function isSupported(supportList, browser, version, semver) {
147
143
  const supportedVersionDetails = supportList[browser];
148
- if (supportedVersionDetails == null)
149
- return false;
144
+ if (supportedVersionDetails == null) return false;
150
145
  const supportedVersion = semver.coerce(supportedVersionDetails.version_added);
151
- if (supportedVersion == null)
152
- return false;
146
+ if (supportedVersion == null) return false;
153
147
  return semver.gte(version, supportedVersion);
154
148
  }
155
149
 
@@ -11,8 +11,7 @@ function createMagicModulePlugin({
11
11
  return {
12
12
  name,
13
13
  async resolveId(id) {
14
- if (id !== module)
15
- return null;
14
+ if (id !== module) return null;
16
15
  const resolved = (typeof alias === "function" ? await alias() : alias) ?? virtualModuleAlias;
17
16
  return {
18
17
  id: resolved,
@@ -20,8 +19,7 @@ function createMagicModulePlugin({
20
19
  };
21
20
  },
22
21
  load: getSource ? async function load(source) {
23
- if (source !== virtualModuleAlias)
24
- return null;
22
+ if (source !== virtualModuleAlias) return null;
25
23
  const code = await getSource.call(this);
26
24
  return {
27
25
  code,
@@ -73,8 +73,7 @@ async function sourceEntriesForProject(project) {
73
73
  exports
74
74
  )) {
75
75
  let targetFile = null;
76
- if (exportCondition == null)
77
- continue;
76
+ if (exportCondition == null) continue;
78
77
  if (typeof exportCondition === "string") {
79
78
  targetFile = exportCondition;
80
79
  } else {
@@ -82,8 +81,7 @@ async function sourceEntriesForProject(project) {
82
81
  (condition) => typeof condition === "string" && condition.startsWith("./build/")
83
82
  );
84
83
  }
85
- if (targetFile == null)
86
- continue;
84
+ if (targetFile == null) continue;
87
85
  const sourceFile = await resolveTargetFileAsSource(targetFile, project);
88
86
  entries[exportPath] = sourceFile;
89
87
  }