@quilted/rollup 0.2.3 → 0.2.5

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 (50) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/build/esm/app.mjs +151 -113
  3. package/build/esm/features/node.mjs +57 -0
  4. package/build/esm/features/react.mjs +22 -0
  5. package/build/esm/features/typescript.mjs +2 -2
  6. package/build/esm/index.mjs +1 -1
  7. package/build/esm/module.mjs +26 -27
  8. package/build/esm/package.mjs +36 -79
  9. package/build/esm/server.mjs +22 -25
  10. package/build/esm/shared/browserslist.mjs +2 -1
  11. package/build/esm/shared/project.mjs +100 -0
  12. package/build/esm/shared/rollup.mjs +4 -1
  13. package/build/tsconfig.tsbuildinfo +1 -1
  14. package/build/typescript/app.d.ts +64 -14
  15. package/build/typescript/app.d.ts.map +1 -1
  16. package/build/typescript/features/node.d.ts +4 -0
  17. package/build/typescript/features/node.d.ts.map +1 -0
  18. package/build/typescript/features/react.d.ts +28 -0
  19. package/build/typescript/features/react.d.ts.map +1 -0
  20. package/build/typescript/features/typescript.d.ts +1 -1
  21. package/build/typescript/features/typescript.d.ts.map +1 -1
  22. package/build/typescript/index.d.ts +1 -1
  23. package/build/typescript/index.d.ts.map +1 -1
  24. package/build/typescript/module.d.ts +3 -4
  25. package/build/typescript/module.d.ts.map +1 -1
  26. package/build/typescript/package.d.ts +3 -5
  27. package/build/typescript/package.d.ts.map +1 -1
  28. package/build/typescript/server.d.ts +4 -3
  29. package/build/typescript/server.d.ts.map +1 -1
  30. package/build/typescript/shared/browserslist.d.ts.map +1 -1
  31. package/build/typescript/shared/project.d.ts +33 -0
  32. package/build/typescript/shared/project.d.ts.map +1 -0
  33. package/build/typescript/shared/rollup.d.ts +2 -1
  34. package/build/typescript/shared/rollup.d.ts.map +1 -1
  35. package/package.json +19 -1
  36. package/source/app.ts +200 -141
  37. package/source/features/node.ts +74 -0
  38. package/source/features/react.ts +26 -0
  39. package/source/features/typescript.ts +1 -1
  40. package/source/index.ts +3 -1
  41. package/source/module.ts +27 -35
  42. package/source/package.ts +37 -109
  43. package/source/server.ts +25 -31
  44. package/source/shared/browserslist.ts +3 -1
  45. package/source/shared/project.ts +150 -0
  46. package/source/shared/rollup.ts +5 -1
  47. package/build/esm/shared/package-json.mjs +0 -16
  48. package/build/esm/shared/path.mjs +0 -7
  49. package/source/shared/package-json.ts +0 -20
  50. package/source/shared/path.ts +0 -5
@@ -1,51 +1,55 @@
1
- import * as path from 'node:path';
2
- import { glob } from 'glob';
3
- import { resolveRoot } from './shared/path.mjs';
1
+ import { Project } from './shared/project.mjs';
4
2
  import { getNodePlugins, removeBuildFiles } from './shared/rollup.mjs';
5
- import { loadPackageJSON } from './shared/package-json.mjs';
6
3
  import { getBrowserGroupTargetDetails, rollupGenerateOptionsForBrowsers } from './shared/browserslist.mjs';
7
4
  import { resolveEnvOption } from './features/env.mjs';
8
5
 
9
6
  async function quiltModule({
10
- root: rootPath = process.cwd(),
7
+ root = process.cwd(),
11
8
  entry,
12
9
  env,
13
10
  assets,
14
11
  graphql = true
15
12
  } = {}) {
16
- const root = resolveRoot(rootPath);
13
+ const project = Project.load(root);
17
14
  const mode = (typeof env === "object" ? env?.mode : env) ?? "production";
18
- const outputDirectory = path.join(root, "build/assets");
15
+ const outputDirectory = project.resolve("build/assets");
19
16
  const minify = assets?.minify ?? true;
20
17
  const hash = assets?.hash ?? "async-only";
21
18
  const bundle = assets?.bundle ?? true;
22
19
  const browserGroup = await getBrowserGroupTargetDetails(assets?.targets, {
23
- root
20
+ root: project.root
24
21
  });
25
22
  const targetFilenamePart = browserGroup.name ? `.${browserGroup.name}` : "";
26
23
  const [
27
24
  { visualizer },
28
25
  { magicModuleEnv, replaceProcessEnv },
29
26
  { sourceCode },
27
+ { tsconfigAliases },
28
+ { monorepoPackageAliases },
29
+ { react },
30
30
  { esnext },
31
- nodePlugins,
32
- packageJSON
31
+ nodePlugins
33
32
  ] = await Promise.all([
34
33
  import('rollup-plugin-visualizer'),
35
34
  import('./features/env.mjs'),
36
35
  import('./features/source-code.mjs'),
36
+ import('./features/typescript.mjs'),
37
+ import('./features/node.mjs'),
38
+ import('./features/react.mjs'),
37
39
  import('./features/esnext.mjs'),
38
- getNodePlugins({ bundle }),
39
- loadPackageJSON(root)
40
+ getNodePlugins({ bundle })
40
41
  ]);
41
- const finalEntry = entry ? path.resolve(root, entry) : await sourceForModule(root, packageJSON);
42
+ const finalEntry = await resolveModuleEntry(entry, project);
42
43
  const plugins = [
43
44
  ...nodePlugins,
44
45
  replaceProcessEnv({ mode }),
45
46
  magicModuleEnv({ ...resolveEnvOption(env), mode }),
46
47
  sourceCode({ mode, targets: browserGroup.browsers }),
48
+ tsconfigAliases({ root: project.root }),
49
+ monorepoPackageAliases({ root: project.root }),
47
50
  esnext({ mode, targets: browserGroup.browsers }),
48
- removeBuildFiles(["build/assets", "build/reports"], { root })
51
+ react(),
52
+ removeBuildFiles(["build/assets", "build/reports"], { root: project.root })
49
53
  ];
50
54
  if (graphql) {
51
55
  const { graphql: graphql2 } = await import('./features/graphql.mjs');
@@ -60,8 +64,7 @@ async function quiltModule({
60
64
  template: "treemap",
61
65
  open: false,
62
66
  brotliSize: true,
63
- filename: path.resolve(
64
- root,
67
+ filename: project.resolve(
65
68
  `build/reports/bundle-visualizer${targetFilenamePart}.html`
66
69
  )
67
70
  })
@@ -69,12 +72,6 @@ async function quiltModule({
69
72
  return {
70
73
  input: finalEntry,
71
74
  plugins,
72
- onwarn(warning, defaultWarn) {
73
- if (warning.code === "MODULE_LEVEL_DIRECTIVE" && /['"]use client['"]/.test(warning.message)) {
74
- return;
75
- }
76
- defaultWarn(warning);
77
- },
78
75
  output: {
79
76
  format: "esm",
80
77
  dir: outputDirectory,
@@ -87,16 +84,18 @@ async function quiltModule({
87
84
  }
88
85
  };
89
86
  }
90
- async function sourceForModule(root, packageJSON) {
91
- const { main, exports } = packageJSON;
87
+ async function resolveModuleEntry(entry, project) {
88
+ if (entry) {
89
+ return project.resolve(entry);
90
+ }
91
+ const { main, exports } = project.packageJSON.raw;
92
92
  const entryFromPackageJSON = main ?? exports?.["."];
93
93
  if (entryFromPackageJSON) {
94
- return path.resolve(root, entryFromPackageJSON);
94
+ return project.resolve(entryFromPackageJSON);
95
95
  }
96
- const possibleSourceFiles = await glob(
96
+ const possibleSourceFiles = await project.glob(
97
97
  "{index,module,entry,input}.{ts,tsx,mjs,js,jsx}",
98
98
  {
99
- cwd: root,
100
99
  nodir: true,
101
100
  absolute: true
102
101
  }
@@ -2,15 +2,13 @@ import * as path from 'node:path';
2
2
  import * as fs from 'node:fs/promises';
3
3
  import { exec as exec$1 } from 'node:child_process';
4
4
  import { promisify } from 'node:util';
5
- import { glob } from 'glob';
6
5
  import { multiline } from './shared/strings.mjs';
7
- import { resolveRoot } from './shared/path.mjs';
6
+ import { Project, sourceEntriesForProject } from './shared/project.mjs';
8
7
  import { getNodePlugins, removeBuildFiles } from './shared/rollup.mjs';
9
- import { loadPackageJSON } from './shared/package-json.mjs';
10
8
  import { getBrowserGroupTargetDetails, rollupGenerateOptionsForBrowsers } from './shared/browserslist.mjs';
11
9
 
12
10
  async function quiltPackage({
13
- root: rootPath = process.cwd(),
11
+ root = process.cwd(),
14
12
  commonjs = false,
15
13
  esnext: explicitESNext,
16
14
  entries,
@@ -20,9 +18,8 @@ async function quiltPackage({
20
18
  graphql = true,
21
19
  customize
22
20
  } = {}) {
23
- const root = resolveRoot(rootPath);
24
- const packageJSON = await loadPackageJSON(root);
25
- const resolvedEntries = entries ?? await sourceEntriesForPackage(root, packageJSON);
21
+ const project = Project.load(root);
22
+ const resolvedEntries = entries ?? await sourceEntriesForProject(project);
26
23
  const includeESNext = explicitESNext ?? Object.keys(resolvedEntries).length > 0;
27
24
  const [esm, esnext] = await Promise.all([
28
25
  quiltPackageESModules({
@@ -47,31 +44,34 @@ async function quiltPackage({
47
44
  return esnext ? [esm, esnext] : [esm];
48
45
  }
49
46
  async function quiltPackageESModules({
50
- root: rootPath = process.cwd(),
47
+ root = process.cwd(),
51
48
  commonjs = false,
52
49
  entries,
53
50
  executable = {},
54
- react,
51
+ react: useReact,
55
52
  bundle,
56
53
  graphql = true,
57
54
  customize
58
55
  } = {}) {
59
- const root = resolveRoot(rootPath);
60
- const outputDirectory = path.resolve(root, "build/esm");
56
+ const project = Project.load(root);
57
+ const outputDirectory = project.resolve("build/esm");
61
58
  const hasExecutables = Object.keys(executable).length > 0;
62
- const [{ sourceCode }, { esnext }, nodePlugins, packageJSON, browserGroup] = await Promise.all([
59
+ const [{ sourceCode }, { react }, { esnext }, nodePlugins, browserGroup] = await Promise.all([
63
60
  import('./features/source-code.mjs'),
61
+ import('./features/react.mjs'),
64
62
  import('./features/esnext.mjs'),
65
63
  getNodePlugins({ bundle }),
66
- loadPackageJSON(root),
67
- getBrowserGroupTargetDetails({ name: "default" }, { root })
64
+ getBrowserGroupTargetDetails({ name: "default" }, { root: project.root })
68
65
  ]);
69
- const resolvedEntries = entries ?? await sourceEntriesForPackage(root, packageJSON);
66
+ const resolvedEntries = entries ?? await sourceEntriesForProject(project);
70
67
  const hasEntries = Object.keys(resolvedEntries).length > 0;
71
- const source = sourceForEntries({ ...resolvedEntries, ...executable }, { root });
68
+ const source = sourceForEntries(
69
+ { ...resolvedEntries, ...executable },
70
+ { root: project.root }
71
+ );
72
72
  const plugins = [
73
73
  ...nodePlugins,
74
- sourceCode({ mode: "production", react }),
74
+ sourceCode({ mode: "production", react: useReact }),
75
75
  esnext({ mode: "production", babel: false }),
76
76
  removeBuildFiles(
77
77
  [
@@ -79,11 +79,14 @@ async function quiltPackageESModules({
79
79
  ...commonjs ? ["build/cjs"] : [],
80
80
  ...hasExecutables ? ["bin"] : []
81
81
  ],
82
- { root }
82
+ { root: project.root }
83
83
  )
84
84
  ];
85
+ if (useReact) {
86
+ plugins.push(react());
87
+ }
85
88
  if (hasExecutables) {
86
- plugins.push(packageExecutables(executable, { root }));
89
+ plugins.push(packageExecutables(executable, { root: project.root }));
87
90
  }
88
91
  if (graphql) {
89
92
  const { graphql: graphql2 } = await import('./features/graphql.mjs');
@@ -121,12 +124,6 @@ async function quiltPackageESModules({
121
124
  const options = {
122
125
  input: source.files,
123
126
  plugins,
124
- onwarn(warning, defaultWarn) {
125
- if (warning.code === "MODULE_LEVEL_DIRECTIVE" && /['"]use client['"]/.test(warning.message)) {
126
- return;
127
- }
128
- defaultWarn(warning);
129
- },
130
127
  output
131
128
  };
132
129
  if (customize) {
@@ -148,29 +145,32 @@ async function quiltPackageESModules({
148
145
  }
149
146
  }
150
147
  async function quiltPackageESNext({
151
- root: rootPath = process.cwd(),
152
- react,
148
+ root = process.cwd(),
149
+ react: useReact,
153
150
  graphql = true,
154
151
  entries,
155
152
  bundle,
156
153
  customize
157
154
  } = {}) {
158
- const root = resolveRoot(rootPath);
159
- const outputDirectory = path.join(root, "build/esnext");
160
- const [{ sourceCode }, { esnext }, nodePlugins, packageJSON] = await Promise.all([
155
+ const project = Project.load(root);
156
+ const outputDirectory = project.resolve("build/esnext");
157
+ const [{ sourceCode }, { react }, { esnext }, nodePlugins] = await Promise.all([
161
158
  import('./features/source-code.mjs'),
159
+ import('./features/react.mjs'),
162
160
  import('./features/esnext.mjs'),
163
- getNodePlugins({ bundle }),
164
- loadPackageJSON(root)
161
+ getNodePlugins({ bundle })
165
162
  ]);
166
- const resolvedEntries = entries ?? await sourceEntriesForPackage(root, packageJSON);
167
- const source = sourceForEntries(resolvedEntries, { root });
163
+ const resolvedEntries = entries ?? await sourceEntriesForProject(project);
164
+ const source = sourceForEntries(resolvedEntries, { root: project.root });
168
165
  const plugins = [
169
166
  ...nodePlugins,
170
- sourceCode({ mode: "production", babel: false, react }),
167
+ sourceCode({ mode: "production", babel: false, react: useReact }),
171
168
  esnext({ mode: "production", babel: false }),
172
- removeBuildFiles(["build/esnext"], { root })
169
+ removeBuildFiles(["build/esnext"], { root: project.root })
173
170
  ];
171
+ if (useReact) {
172
+ plugins.push(react());
173
+ }
174
174
  if (graphql) {
175
175
  const { graphql: graphql2 } = await import('./features/graphql.mjs');
176
176
  plugins.push(graphql2({ manifest: false }));
@@ -292,48 +292,5 @@ function sourceForEntries(entries, { root }) {
292
292
  }
293
293
  return { root: sourceRoot, files: sourceEntryFiles };
294
294
  }
295
- async function sourceEntriesForPackage(root, packageJSON) {
296
- const { main, exports } = packageJSON;
297
- const entries = {};
298
- if (typeof main === "string") {
299
- entries["."] = await resolveTargetFileAsSource(main, root);
300
- }
301
- if (typeof exports === "string") {
302
- entries["."] = await resolveTargetFileAsSource(exports, root);
303
- return entries;
304
- } else if (exports == null || typeof exports !== "object") {
305
- return entries;
306
- }
307
- for (const [exportPath, exportCondition] of Object.entries(
308
- exports
309
- )) {
310
- let targetFile = null;
311
- if (exportCondition == null)
312
- continue;
313
- if (typeof exportCondition === "string") {
314
- targetFile = exportCondition;
315
- } else {
316
- targetFile ??= exportCondition["source"] ?? exportCondition["quilt:source"] ?? exportCondition["quilt:esnext"] ?? Object.values(exportCondition).find(
317
- (condition) => typeof condition === "string" && condition.startsWith("./build/")
318
- );
319
- }
320
- if (targetFile == null)
321
- continue;
322
- const sourceFile = await resolveTargetFileAsSource(targetFile, root);
323
- entries[exportPath] = sourceFile;
324
- }
325
- return entries;
326
- }
327
- async function resolveTargetFileAsSource(file, root) {
328
- const sourceFile = file.includes("/build/") ? (await glob(
329
- file.replace(/[/]build[/][^/]+[/]/, "/*/").replace(/(\.d\.ts|\.[\w]+)$/, ".*"),
330
- {
331
- cwd: root,
332
- absolute: true,
333
- ignore: [path.resolve(root, file)]
334
- }
335
- ))[0] : path.resolve(root, file);
336
- return sourceFile;
337
- }
338
295
 
339
296
  export { packageExecutables, quiltPackage, quiltPackageESModules, quiltPackageESNext };
@@ -1,8 +1,5 @@
1
- import * as path from 'node:path';
2
- import { glob } from 'glob';
1
+ import { Project } from './shared/project.mjs';
3
2
  import { getNodePlugins, removeBuildFiles } from './shared/rollup.mjs';
4
- import { resolveRoot } from './shared/path.mjs';
5
- import { loadPackageJSON } from './shared/package-json.mjs';
6
3
  import { magicModuleRequestRouterEntry } from './features/request-router.mjs';
7
4
  import { resolveEnvOption } from './features/env.mjs';
8
5
  import { MAGIC_MODULE_ENTRY, MAGIC_MODULE_REQUEST_ROUTER } from './constants.mjs';
@@ -18,9 +15,9 @@ async function quiltServer({
18
15
  port,
19
16
  host
20
17
  } = {}) {
21
- const root = resolveRoot(rootPath);
18
+ const project = Project.load(rootPath);
22
19
  const mode = (typeof env === "object" ? env?.mode : void 0) ?? "production";
23
- const outputDirectory = path.join(root, "build/server");
20
+ const outputDirectory = project.resolve("build/server");
24
21
  const minify = output?.minify ?? false;
25
22
  const bundle = output?.bundle;
26
23
  const hash = output?.hash ?? "async-only";
@@ -29,26 +26,33 @@ async function quiltServer({
29
26
  { visualizer },
30
27
  { magicModuleEnv, replaceProcessEnv },
31
28
  { sourceCode },
29
+ { tsconfigAliases },
30
+ { monorepoPackageAliases },
31
+ { react },
32
32
  { esnext },
33
- nodePlugins,
34
- packageJSON
33
+ nodePlugins
35
34
  ] = await Promise.all([
36
35
  import('rollup-plugin-visualizer'),
37
36
  import('./features/env.mjs'),
38
37
  import('./features/source-code.mjs'),
38
+ import('./features/typescript.mjs'),
39
+ import('./features/node.mjs'),
40
+ import('./features/react.mjs'),
39
41
  import('./features/esnext.mjs'),
40
- getNodePlugins({ bundle }),
41
- loadPackageJSON(root)
42
+ getNodePlugins({ bundle })
42
43
  ]);
43
- const serverEntry = entry ? path.resolve(root, entry) : await sourceForServer(root, packageJSON);
44
+ const serverEntry = entry ? project.resolve(entry) : await sourceForServer(project);
44
45
  const finalEntry = format === "request-router" ? MAGIC_MODULE_ENTRY : serverEntry ?? MAGIC_MODULE_ENTRY;
45
46
  const plugins = [
46
47
  ...nodePlugins,
47
48
  replaceProcessEnv({ mode }),
48
49
  magicModuleEnv({ ...resolveEnvOption(env), mode }),
49
50
  sourceCode({ mode, targets: ["current node"] }),
51
+ tsconfigAliases({ root: project.root }),
52
+ monorepoPackageAliases({ root: project.root }),
53
+ react(),
50
54
  esnext({ mode, targets: ["current node"] }),
51
- removeBuildFiles(["build/server", "build/reports"], { root })
55
+ removeBuildFiles(["build/server", "build/reports"], { root: project.root })
52
56
  ];
53
57
  if (format === "request-router") {
54
58
  plugins.push(
@@ -76,18 +80,12 @@ async function quiltServer({
76
80
  template: "treemap",
77
81
  open: false,
78
82
  brotliSize: true,
79
- filename: path.resolve(root, `build/reports/bundle-visualizer.html`)
83
+ filename: project.resolve(`build/reports/bundle-visualizer.html`)
80
84
  })
81
85
  );
82
86
  return {
83
87
  input: finalEntry === MAGIC_MODULE_ENTRY ? { server: finalEntry } : finalEntry,
84
88
  plugins,
85
- onwarn(warning, defaultWarn) {
86
- if (warning.code === "MODULE_LEVEL_DIRECTIVE" && /['"]use client['"]/.test(warning.message)) {
87
- return;
88
- }
89
- defaultWarn(warning);
90
- },
91
89
  output: {
92
90
  format: outputFormat === "commonjs" || outputFormat === "cjs" ? "cjs" : "esm",
93
91
  dir: outputDirectory,
@@ -98,16 +96,15 @@ async function quiltServer({
98
96
  }
99
97
  };
100
98
  }
101
- async function sourceForServer(root, packageJSON) {
102
- const { main, exports } = packageJSON;
99
+ async function sourceForServer(project) {
100
+ const { main, exports } = project.packageJSON.raw;
103
101
  const entryFromPackageJSON = main ?? exports?.["."];
104
102
  if (entryFromPackageJSON) {
105
- return path.resolve(root, entryFromPackageJSON);
103
+ return project.resolve(entryFromPackageJSON);
106
104
  }
107
- const possibleSourceFiles = await glob(
105
+ const possibleSourceFiles = await project.glob(
108
106
  "{index,server,service,backend,entry,input}.{ts,tsx,mjs,js,jsx}",
109
107
  {
110
- cwd: root,
111
108
  nodir: true,
112
109
  absolute: true
113
110
  }
@@ -115,4 +112,4 @@ async function sourceForServer(root, packageJSON) {
115
112
  return possibleSourceFiles[0];
116
113
  }
117
114
 
118
- export { quiltServer };
115
+ export { MAGIC_MODULE_ENTRY, MAGIC_MODULE_REQUEST_ROUTER, quiltServer };
@@ -8,7 +8,8 @@ async function getBrowserGroupTargetDetails(targetSelection = {}, { root } = {})
8
8
  const targetName = targets.name ?? "default";
9
9
  return config[targetName] ?? ["defaults"];
10
10
  })();
11
- return { name: targets.name, browsers: browserslist(targetBrowsers) };
11
+ const browsers = browserslist(targetBrowsers);
12
+ return { name: targets.name, browsers };
12
13
  }
13
14
  async function getBrowserGroups({
14
15
  root = process.cwd()
@@ -0,0 +1,100 @@
1
+ import * as path from 'node:path';
2
+ import { readFileSync } from 'node:fs';
3
+ import { fileURLToPath } from 'node:url';
4
+ import { glob } from 'glob';
5
+
6
+ const PROJECT_CACHE = /* @__PURE__ */ new Map();
7
+ class Project {
8
+ static load(root) {
9
+ const resolvedRoot = resolveRoot(root);
10
+ let project = PROJECT_CACHE.get(resolvedRoot);
11
+ if (project == null) {
12
+ project = new Project(resolvedRoot);
13
+ PROJECT_CACHE.set(resolvedRoot, project);
14
+ }
15
+ return project;
16
+ }
17
+ root;
18
+ get path() {
19
+ return this.root;
20
+ }
21
+ get name() {
22
+ return this.packageJSON.name;
23
+ }
24
+ #packageJSON;
25
+ get packageJSON() {
26
+ this.#packageJSON ??= new PackageJSON(this.root);
27
+ return this.#packageJSON;
28
+ }
29
+ constructor(root) {
30
+ this.root = resolveRoot(root);
31
+ }
32
+ resolve(...segments) {
33
+ return path.resolve(this.root, ...segments);
34
+ }
35
+ glob(pattern, options) {
36
+ return glob(pattern, {
37
+ ...options,
38
+ absolute: true,
39
+ cwd: this.root
40
+ });
41
+ }
42
+ }
43
+ class PackageJSON {
44
+ raw;
45
+ path;
46
+ get name() {
47
+ return this.raw.name;
48
+ }
49
+ constructor(rootOrPath) {
50
+ this.path = rootOrPath.endsWith("package.json") ? rootOrPath : path.join(rootOrPath, "package.json");
51
+ this.raw = JSON.parse(readFileSync(this.path, "utf8"));
52
+ }
53
+ }
54
+ function resolveRoot(root) {
55
+ return typeof root === "string" ? root : fileURLToPath(root);
56
+ }
57
+ async function sourceEntriesForProject(project) {
58
+ const { main, exports } = project.packageJSON.raw;
59
+ const entries = {};
60
+ if (typeof main === "string") {
61
+ entries["."] = await resolveTargetFileAsSource(main, project);
62
+ }
63
+ if (typeof exports === "string") {
64
+ entries["."] = await resolveTargetFileAsSource(exports, project);
65
+ return entries;
66
+ } else if (exports == null || typeof exports !== "object") {
67
+ return entries;
68
+ }
69
+ for (const [exportPath, exportCondition] of Object.entries(
70
+ exports
71
+ )) {
72
+ let targetFile = null;
73
+ if (exportCondition == null)
74
+ continue;
75
+ if (typeof exportCondition === "string") {
76
+ targetFile = exportCondition;
77
+ } else {
78
+ targetFile ??= exportCondition["source"] ?? exportCondition["quilt:source"] ?? exportCondition["quilt:esnext"] ?? Object.values(exportCondition).find(
79
+ (condition) => typeof condition === "string" && condition.startsWith("./build/")
80
+ );
81
+ }
82
+ if (targetFile == null)
83
+ continue;
84
+ const sourceFile = await resolveTargetFileAsSource(targetFile, project);
85
+ entries[exportPath] = sourceFile;
86
+ }
87
+ return entries;
88
+ }
89
+ async function resolveTargetFileAsSource(file, project) {
90
+ const sourceFile = file.includes("/build/") ? (await project.glob(
91
+ file.replace(/[/]build[/][^/]+[/]/, "/*/").replace(/(\.d\.ts|\.[\w]+)$/, ".*"),
92
+ {
93
+ absolute: true,
94
+ ignore: [project.resolve(file)]
95
+ }
96
+ ))[0] : project.resolve(file);
97
+ return sourceFile;
98
+ }
99
+
100
+ export { PackageJSON, Project, sourceEntriesForProject };
@@ -28,6 +28,9 @@ function removeBuildFiles(patterns, { root = process.cwd() } = {}) {
28
28
  }
29
29
  };
30
30
  }
31
+ function normalizeRollupInput(input) {
32
+ return Array.isArray(input) && input.length === 0 ? void 0 : input;
33
+ }
31
34
  async function getNodePlugins({
32
35
  bundle = {}
33
36
  } = {}) {
@@ -100,4 +103,4 @@ async function getNodePlugins({
100
103
  ];
101
104
  }
102
105
 
103
- export { getNodePlugins, removeBuildFiles, smartReplace };
106
+ export { getNodePlugins, normalizeRollupInput, removeBuildFiles, smartReplace };