@quilted/rollup 0.2.4 → 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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @quilted/rollup
2
2
 
3
+ ## 0.2.5
4
+
5
+ ### Patch Changes
6
+
7
+ - [`465883e1`](https://github.com/lemonmade/quilt/commit/465883e12571bee9d6e8c8d517ebf6da384687b2) Thanks [@lemonmade](https://github.com/lemonmade)! - Add support for automatic in-repo source aliases
8
+
3
9
  ## 0.2.4
4
10
 
5
11
  ### Patch Changes
package/build/esm/app.mjs CHANGED
@@ -1,6 +1,5 @@
1
1
  import * as path from 'node:path';
2
2
  import * as fs from 'node:fs/promises';
3
- import { glob } from 'glob';
4
3
  import { createRequire } from 'node:module';
5
4
  import { MAGIC_MODULE_ENTRY, MAGIC_MODULE_APP_COMPONENT, MAGIC_MODULE_REQUEST_ROUTER, MAGIC_MODULE_BROWSER_ASSETS } from './constants.mjs';
6
5
  import { resolveEnvOption } from './features/env.mjs';
@@ -8,12 +7,11 @@ import { multiline } from './shared/strings.mjs';
8
7
  import { getNodePlugins, removeBuildFiles, normalizeRollupInput } from './shared/rollup.mjs';
9
8
  import { createMagicModulePlugin } from './shared/magic-module.mjs';
10
9
  import { getBrowserGroups, getBrowserGroupTargetDetails, targetsSupportModules, rollupGenerateOptionsForBrowsers, getBrowserGroupRegularExpressions } from './shared/browserslist.mjs';
11
- import { loadPackageJSON } from './shared/package-json.mjs';
12
- import { resolveRoot } from './shared/path.mjs';
10
+ import { Project } from './shared/project.mjs';
13
11
 
14
12
  const require = createRequire(import.meta.url);
15
13
  async function quiltAppOptions({
16
- root: rootPath = process.cwd(),
14
+ root = process.cwd(),
17
15
  app,
18
16
  env,
19
17
  graphql,
@@ -21,15 +19,15 @@ async function quiltAppOptions({
21
19
  browser: browserOptions,
22
20
  server: serverOptions
23
21
  } = {}) {
24
- const root = resolveRoot(rootPath);
25
- const browserGroups = await getBrowserGroups({ root });
22
+ const project = Project.load(root);
23
+ const browserGroups = await getBrowserGroups({ root: project.root });
26
24
  const browserGroupEntries = Object.entries(browserGroups);
27
25
  const hasMultipleBrowserGroups = browserGroupEntries.length > 1;
28
26
  const optionPromises = [];
29
27
  browserGroupEntries.forEach(([name, browsers], index) => {
30
28
  optionPromises.push(
31
29
  quiltAppBrowserOptions({
32
- root,
30
+ root: project.root,
33
31
  app,
34
32
  graphql,
35
33
  ...browserOptions,
@@ -51,7 +49,7 @@ async function quiltAppOptions({
51
49
  });
52
50
  optionPromises.push(
53
51
  quiltAppServerOptions({
54
- root,
52
+ root: project.root,
55
53
  app,
56
54
  graphql,
57
55
  ...serverOptions,
@@ -65,12 +63,12 @@ async function quiltAppOptions({
65
63
  return Promise.all(optionPromises);
66
64
  }
67
65
  async function quiltAppBrowserOptions(options = {}) {
68
- const { root: rootPath = process.cwd(), assets } = options;
69
- const root = resolveRoot(rootPath);
66
+ const { root = process.cwd(), assets } = options;
67
+ const project = Project.load(root);
70
68
  const [plugins, browserGroup] = await Promise.all([
71
69
  quiltAppBrowser(options),
72
70
  getBrowserGroupTargetDetails(assets?.targets, {
73
- root
71
+ root: project.root
74
72
  })
75
73
  ]);
76
74
  const targetFilenamePart = browserGroup.name ? `.${browserGroup.name}` : "";
@@ -82,7 +80,7 @@ async function quiltAppBrowserOptions(options = {}) {
82
80
  plugins,
83
81
  output: {
84
82
  format: isESM ? "esm" : "systemjs",
85
- dir: path.resolve(root, `build/assets`),
83
+ dir: project.resolve(`build/assets`),
86
84
  entryFileNames: `[name]${targetFilenamePart}.[hash].js`,
87
85
  assetFileNames: `[name]${targetFilenamePart}.[hash].[ext]`,
88
86
  chunkFileNames: `[name]${targetFilenamePart}.[hash].js`,
@@ -92,7 +90,7 @@ async function quiltAppBrowserOptions(options = {}) {
92
90
  };
93
91
  }
94
92
  async function quiltAppBrowser({
95
- root: rootPath = process.cwd(),
93
+ root = process.cwd(),
96
94
  app,
97
95
  entry,
98
96
  env,
@@ -100,13 +98,13 @@ async function quiltAppBrowser({
100
98
  module,
101
99
  graphql = true
102
100
  } = {}) {
103
- const root = resolveRoot(rootPath);
101
+ const project = Project.load(root);
104
102
  const mode = (typeof env === "object" ? env?.mode : env) ?? "production";
105
103
  const minify = assets?.minify ?? mode === "production";
106
104
  const baseURL = assets?.baseURL ?? "/assets/";
107
105
  const assetsInline = assets?.inline ?? true;
108
106
  const browserGroup = await getBrowserGroupTargetDetails(assets?.targets, {
109
- root
107
+ root: project.root
110
108
  });
111
109
  const targetFilenamePart = browserGroup.name ? `.${browserGroup.name}` : "";
112
110
  const [
@@ -114,6 +112,7 @@ async function quiltAppBrowser({
114
112
  { magicModuleEnv, replaceProcessEnv },
115
113
  { sourceCode },
116
114
  { tsconfigAliases },
115
+ { monorepoPackageAliases },
117
116
  { react },
118
117
  { css },
119
118
  { assetManifest, rawAssets, staticAssets },
@@ -121,13 +120,13 @@ async function quiltAppBrowser({
121
120
  { systemJS },
122
121
  { workers },
123
122
  { esnext },
124
- nodePlugins,
125
- packageJSON
123
+ nodePlugins
126
124
  ] = await Promise.all([
127
125
  import('rollup-plugin-visualizer'),
128
126
  import('./features/env.mjs'),
129
127
  import('./features/source-code.mjs'),
130
128
  import('./features/typescript.mjs'),
129
+ import('./features/node.mjs'),
131
130
  import('./features/react.mjs'),
132
131
  import('./features/css.mjs'),
133
132
  import('./features/assets.mjs'),
@@ -135,11 +134,10 @@ async function quiltAppBrowser({
135
134
  import('./features/system-js.mjs'),
136
135
  import('./features/workers.mjs'),
137
136
  import('./features/esnext.mjs'),
138
- getNodePlugins({ bundle: true }),
139
- loadPackageJSON(root)
137
+ getNodePlugins({ bundle: true })
140
138
  ]);
141
139
  const plugins = [
142
- quiltAppBrowserInput({ root, entry }),
140
+ quiltAppBrowserInput({ root: project.root, entry }),
143
141
  ...nodePlugins,
144
142
  systemJS({ minify }),
145
143
  replaceProcessEnv({ mode }),
@@ -176,29 +174,30 @@ async function quiltAppBrowser({
176
174
  asyncModules({
177
175
  baseURL,
178
176
  preload: true,
179
- moduleID: ({ imported }) => path.relative(root, imported)
177
+ moduleID: ({ imported }) => path.relative(project.root, imported)
180
178
  }),
181
179
  workers({
182
180
  baseURL,
183
181
  outputOptions: {
184
182
  format: "iife",
185
183
  inlineDynamicImports: true,
186
- dir: path.resolve(root, `build/assets`),
184
+ dir: project.resolve(`build/assets`),
187
185
  entryFileNames: `[name]${targetFilenamePart}.[hash].js`,
188
186
  assetFileNames: `[name]${targetFilenamePart}.[hash].[ext]`,
189
187
  chunkFileNames: `[name]${targetFilenamePart}.[hash].js`
190
188
  }
191
189
  }),
192
- tsconfigAliases({ root })
190
+ tsconfigAliases({ root: project.root }),
191
+ monorepoPackageAliases({ root: project.root })
193
192
  ];
194
193
  if (assets?.clean ?? true) {
195
194
  plugins.push(
196
195
  removeBuildFiles(["build/assets", "build/manifests", "build/reports"], {
197
- root
196
+ root: project.root
198
197
  })
199
198
  );
200
199
  }
201
- const appEntry = await resolveAppEntry(app, { root, packageJSON });
200
+ const appEntry = await resolveAppEntry(app, project);
202
201
  if (appEntry) {
203
202
  plugins.push(magicModuleAppComponent({ entry: appEntry }));
204
203
  }
@@ -207,8 +206,7 @@ async function quiltAppBrowser({
207
206
  const { graphql: graphql2 } = await import('./features/graphql.mjs');
208
207
  plugins.push(
209
208
  graphql2({
210
- manifest: path.resolve(
211
- root,
209
+ manifest: project.resolve(
212
210
  `build/manifests/graphql${targetFilenamePart}.json`
213
211
  )
214
212
  })
@@ -226,18 +224,14 @@ async function quiltAppBrowser({
226
224
  assetManifest({
227
225
  baseURL,
228
226
  cacheKey,
229
- file: path.resolve(
230
- root,
231
- `build/manifests/assets${targetFilenamePart}.json`
232
- ),
227
+ file: project.resolve(`build/manifests/assets${targetFilenamePart}.json`),
233
228
  priority: assets?.priority
234
229
  }),
235
230
  visualizer({
236
231
  template: "treemap",
237
232
  open: false,
238
233
  brotliSize: true,
239
- filename: path.resolve(
240
- root,
234
+ filename: project.resolve(
241
235
  `build/reports/bundle-visualizer${targetFilenamePart}.html`
242
236
  )
243
237
  })
@@ -245,15 +239,14 @@ async function quiltAppBrowser({
245
239
  return plugins;
246
240
  }
247
241
  function quiltAppBrowserInput({
248
- root: rootPath = process.cwd(),
242
+ root = process.cwd(),
249
243
  entry
250
244
  } = {}) {
251
- const root = resolveRoot(rootPath);
245
+ const project = Project.load(root);
252
246
  return {
253
247
  name: "@quilted/app-browser/input",
254
248
  async options(options) {
255
- const finalEntry = normalizeRollupInput(options.input) ?? (entry ? path.resolve(root, entry) : await glob("{browser,client,web}.{ts,tsx,mjs,js,jsx}", {
256
- cwd: root,
249
+ const finalEntry = normalizeRollupInput(options.input) ?? (entry ? project.resolve(entry) : await project.glob("{browser,client,web}.{ts,tsx,mjs,js,jsx}", {
257
250
  nodir: true,
258
251
  absolute: true
259
252
  }).then((files) => files[0])) ?? MAGIC_MODULE_ENTRY;
@@ -267,8 +260,8 @@ function quiltAppBrowserInput({
267
260
  };
268
261
  }
269
262
  async function quiltAppServerOptions(options = {}) {
270
- const { root: rootPath = process.cwd(), output } = options;
271
- const root = resolveRoot(rootPath);
263
+ const { root = process.cwd(), output } = options;
264
+ const project = Project.load(root);
272
265
  const hash = output?.hash ?? "async-only";
273
266
  const outputFormat = output?.format ?? "esmodules";
274
267
  const plugins = await quiltAppServer(options);
@@ -276,7 +269,7 @@ async function quiltAppServerOptions(options = {}) {
276
269
  plugins,
277
270
  output: {
278
271
  format: outputFormat === "commonjs" || outputFormat === "cjs" ? "cjs" : "esm",
279
- dir: path.resolve(root, `build/server`),
272
+ dir: project.resolve(`build/server`),
280
273
  entryFileNames: `[name]${hash === true ? `.[hash]` : ""}.js`,
281
274
  chunkFileNames: `[name]${hash === true || hash === "async-only" ? `.[hash]` : ""}.js`,
282
275
  assetFileNames: `[name]${hash === true ? `.[hash]` : ""}.[ext]`,
@@ -285,7 +278,7 @@ async function quiltAppServerOptions(options = {}) {
285
278
  };
286
279
  }
287
280
  async function quiltAppServer({
288
- root: rootPath = process.cwd(),
281
+ root = process.cwd(),
289
282
  app,
290
283
  env,
291
284
  entry,
@@ -294,7 +287,7 @@ async function quiltAppServer({
294
287
  assets,
295
288
  output
296
289
  } = {}) {
297
- const root = resolveRoot(rootPath);
290
+ const project = Project.load(root);
298
291
  const mode = (typeof env === "object" ? env?.mode : env) ?? "production";
299
292
  const baseURL = assets?.baseURL ?? "/assets/";
300
293
  const assetsInline = assets?.inline ?? true;
@@ -306,27 +299,27 @@ async function quiltAppServer({
306
299
  { sourceCode },
307
300
  { react },
308
301
  { tsconfigAliases },
302
+ { monorepoPackageAliases },
309
303
  { css },
310
304
  { rawAssets, staticAssets },
311
305
  { asyncModules },
312
306
  { esnext },
313
- nodePlugins,
314
- packageJSON
307
+ nodePlugins
315
308
  ] = await Promise.all([
316
309
  import('rollup-plugin-visualizer'),
317
310
  import('./features/env.mjs'),
318
311
  import('./features/source-code.mjs'),
319
312
  import('./features/react.mjs'),
320
313
  import('./features/typescript.mjs'),
314
+ import('./features/node.mjs'),
321
315
  import('./features/css.mjs'),
322
316
  import('./features/assets.mjs'),
323
317
  import('./features/async.mjs'),
324
318
  import('./features/esnext.mjs'),
325
- getNodePlugins({ bundle }),
326
- loadPackageJSON(root)
319
+ getNodePlugins({ bundle })
327
320
  ]);
328
321
  const plugins = [
329
- quiltAppServerInput({ root, entry, format }),
322
+ quiltAppServerInput({ root: project.root, entry, format }),
330
323
  ...nodePlugins,
331
324
  replaceProcessEnv({ mode }),
332
325
  magicModuleEnv({ ...resolveEnvOption(env), mode }),
@@ -361,17 +354,17 @@ async function quiltAppServer({
361
354
  asyncModules({
362
355
  baseURL,
363
356
  preload: false,
364
- moduleID: ({ imported }) => path.relative(root, imported)
357
+ moduleID: ({ imported }) => path.relative(project.root, imported)
365
358
  }),
366
- removeBuildFiles(["build/server"], { root }),
367
- tsconfigAliases({ root })
359
+ removeBuildFiles(["build/server"], { root: project.root }),
360
+ tsconfigAliases({ root: project.root }),
361
+ monorepoPackageAliases({ root: project.root })
368
362
  ];
369
- const appEntry = await resolveAppEntry(app, { root, packageJSON });
363
+ const appEntry = await resolveAppEntry(app, project);
370
364
  if (appEntry) {
371
365
  plugins.push(magicModuleAppComponent({ entry: appEntry }));
372
366
  }
373
- const serverEntry = entry ? path.resolve(root, entry) : await glob("{server,service,backend}.{ts,tsx,mjs,js,jsx}", {
374
- cwd: root,
367
+ const serverEntry = entry ? project.resolve(entry) : await project.glob("{server,service,backend}.{ts,tsx,mjs,js,jsx}", {
375
368
  nodir: true,
376
369
  absolute: true
377
370
  }).then((files) => files[0]);
@@ -395,27 +388,23 @@ async function quiltAppServer({
395
388
  template: "treemap",
396
389
  open: false,
397
390
  brotliSize: false,
398
- filename: path.resolve(
399
- root,
400
- `build/reports/bundle-visualizer.server.html`
401
- )
391
+ filename: project.resolve(`build/reports/bundle-visualizer.server.html`)
402
392
  })
403
393
  );
404
394
  return plugins;
405
395
  }
406
396
  function quiltAppServerInput({
407
- root: rootPath = process.cwd(),
397
+ root = process.cwd(),
408
398
  entry,
409
399
  format = "request-router"
410
400
  } = {}) {
411
- const root = resolveRoot(rootPath);
401
+ const project = Project.load(root);
412
402
  return {
413
403
  name: "@quilted/app-server/input",
414
404
  async options(options) {
415
405
  let finalEntry = normalizeRollupInput(options.input);
416
406
  if (!finalEntry) {
417
- const serverEntry = entry ? path.resolve(root, entry) : await glob("{server,service,backend}.{ts,tsx,mjs,js,jsx}", {
418
- cwd: root,
407
+ const serverEntry = entry ? project.resolve(entry) : await project.glob("{server,service,backend}.{ts,tsx,mjs,js,jsx}", {
419
408
  nodir: true,
420
409
  absolute: true
421
410
  }).then((files) => files[0]);
@@ -549,8 +538,8 @@ function magicModuleAppAssetManifests() {
549
538
  name: "@quilted/magic-module/asset-manifests",
550
539
  module: MAGIC_MODULE_BROWSER_ASSETS,
551
540
  async source() {
552
- const { glob: glob2 } = await import('glob');
553
- const manifestFiles = await glob2("assets*.json", {
541
+ const { glob } = await import('glob');
542
+ const manifestFiles = await glob("assets*.json", {
554
543
  nodir: true,
555
544
  absolute: true,
556
545
  cwd: path.resolve(`build/manifests`)
@@ -679,19 +668,19 @@ function createManualChunksSorter() {
679
668
  return `${bundleBaseName}-${relativeId.split(path.sep)[0]?.split(".")[0]}`;
680
669
  };
681
670
  }
682
- async function resolveAppEntry(entry, { root, packageJSON }) {
671
+ async function resolveAppEntry(entry, project) {
683
672
  if (entry) {
684
- return path.resolve(root, entry);
673
+ return project.resolve(entry);
685
674
  }
686
- if (typeof packageJSON.main === "string") {
687
- return path.resolve(root, packageJSON.main);
675
+ const { packageJSON } = project;
676
+ if (typeof packageJSON.raw.main === "string") {
677
+ return project.resolve(packageJSON.raw.main);
688
678
  }
689
- const rootEntry = packageJSON.exports?.["."];
679
+ const rootEntry = packageJSON.raw.exports?.["."];
690
680
  if (typeof rootEntry === "string") {
691
- return path.resolve(root, rootEntry);
681
+ return project.resolve(rootEntry);
692
682
  }
693
- const globbed = await glob("{App,app,index}.{ts,tsx,mjs,js,jsx}", {
694
- cwd: root,
683
+ const globbed = await project.glob("{App,app,index}.{ts,tsx,mjs,js,jsx}", {
695
684
  nodir: true,
696
685
  absolute: true
697
686
  });
@@ -0,0 +1,57 @@
1
+ import { realpathSync } from 'node:fs';
2
+ import { Project, sourceEntriesForProject } from '../shared/project.mjs';
3
+
4
+ async function monorepoPackageAliases({
5
+ root = process.cwd()
6
+ } = {}) {
7
+ const project = Project.load(root);
8
+ const seenDependencies = /* @__PURE__ */ new Set();
9
+ const seenProjects = /* @__PURE__ */ new Set();
10
+ function processProject(project2) {
11
+ const { dependencies, devDependencies } = project2.packageJSON.raw;
12
+ for (const pkg of Object.keys({ ...dependencies, ...devDependencies })) {
13
+ if (seenDependencies.has(pkg))
14
+ continue;
15
+ seenDependencies.add(pkg);
16
+ let packageRoot;
17
+ try {
18
+ packageRoot = realpathSync(project2.resolve("node_modules", pkg));
19
+ } catch {
20
+ }
21
+ if (packageRoot == null || packageRoot.includes("node_modules") || packageRoot === root) {
22
+ continue;
23
+ }
24
+ const packageProject = Project.load(packageRoot);
25
+ if (seenProjects.has(packageProject))
26
+ continue;
27
+ seenProjects.add(packageProject);
28
+ processProject(packageProject);
29
+ }
30
+ }
31
+ processProject(project);
32
+ const [{ default: alias }, projectsWithEntries] = await Promise.all([
33
+ import('@rollup/plugin-alias'),
34
+ Promise.all(
35
+ Array.from(seenProjects, async (project2) => {
36
+ const entries = await sourceEntriesForProject(project2);
37
+ return { project: project2, entries };
38
+ })
39
+ )
40
+ ]);
41
+ const aliases = [];
42
+ for (const { project: project2, entries } of projectsWithEntries) {
43
+ const { name } = project2;
44
+ for (const [entry, source] of Object.entries(entries)) {
45
+ const entryName = entry === "." ? name : `${name}/${entry}`;
46
+ aliases.push({
47
+ find: new RegExp(`^${entryName}$`),
48
+ replacement: source
49
+ });
50
+ }
51
+ }
52
+ return alias({
53
+ entries: aliases
54
+ });
55
+ }
56
+
57
+ export { monorepoPackageAliases };
@@ -1,26 +1,23 @@
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 [
@@ -28,30 +25,31 @@ async function quiltModule({
28
25
  { magicModuleEnv, replaceProcessEnv },
29
26
  { sourceCode },
30
27
  { tsconfigAliases },
28
+ { monorepoPackageAliases },
31
29
  { react },
32
30
  { esnext },
33
- nodePlugins,
34
- packageJSON
31
+ nodePlugins
35
32
  ] = await Promise.all([
36
33
  import('rollup-plugin-visualizer'),
37
34
  import('./features/env.mjs'),
38
35
  import('./features/source-code.mjs'),
39
36
  import('./features/typescript.mjs'),
37
+ import('./features/node.mjs'),
40
38
  import('./features/react.mjs'),
41
39
  import('./features/esnext.mjs'),
42
- getNodePlugins({ bundle }),
43
- loadPackageJSON(root)
40
+ getNodePlugins({ bundle })
44
41
  ]);
45
- const finalEntry = entry ? path.resolve(root, entry) : await sourceForModule(root, packageJSON);
42
+ const finalEntry = await resolveModuleEntry(entry, project);
46
43
  const plugins = [
47
44
  ...nodePlugins,
48
45
  replaceProcessEnv({ mode }),
49
46
  magicModuleEnv({ ...resolveEnvOption(env), mode }),
50
47
  sourceCode({ mode, targets: browserGroup.browsers }),
51
- tsconfigAliases({ root }),
48
+ tsconfigAliases({ root: project.root }),
49
+ monorepoPackageAliases({ root: project.root }),
52
50
  esnext({ mode, targets: browserGroup.browsers }),
53
51
  react(),
54
- removeBuildFiles(["build/assets", "build/reports"], { root })
52
+ removeBuildFiles(["build/assets", "build/reports"], { root: project.root })
55
53
  ];
56
54
  if (graphql) {
57
55
  const { graphql: graphql2 } = await import('./features/graphql.mjs');
@@ -66,8 +64,7 @@ async function quiltModule({
66
64
  template: "treemap",
67
65
  open: false,
68
66
  brotliSize: true,
69
- filename: path.resolve(
70
- root,
67
+ filename: project.resolve(
71
68
  `build/reports/bundle-visualizer${targetFilenamePart}.html`
72
69
  )
73
70
  })
@@ -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
  }