prebundle 1.1.0-beta.3 → 1.1.0-beta.4

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/dist/helper.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { Config, DependencyConfig, ParsedTask } from './types.js';
2
- export declare function findDepPath(name: string): string;
2
+ export declare function findDepPath(name: string): string | null;
3
3
  export declare const resolveConfig: () => Promise<Config>;
4
4
  export declare function parseTasks(dependencies: Array<string | DependencyConfig>): ParsedTask[];
5
5
  export declare function pick<T, U extends keyof T>(obj: T, keys: ReadonlyArray<U>): Pick<T, U>;
package/dist/helper.js CHANGED
@@ -4,14 +4,19 @@ import { cwd, DIST_DIR } from './constant.js';
4
4
  import { createRequire } from 'node:module';
5
5
  const require = createRequire(import.meta.url);
6
6
  export function findDepPath(name) {
7
- let entry = dirname(require.resolve(join(name), { paths: [cwd] }));
8
- while (!dirname(entry).endsWith('node_modules')) {
9
- entry = dirname(entry);
7
+ try {
8
+ let entry = dirname(require.resolve(join(name), { paths: [cwd] }));
9
+ while (!dirname(entry).endsWith('node_modules')) {
10
+ entry = dirname(entry);
11
+ }
12
+ if (name.includes('/')) {
13
+ return join(dirname(entry), name);
14
+ }
15
+ return entry;
10
16
  }
11
- if (name.includes('/')) {
12
- return join(dirname(entry), name);
17
+ catch (err) {
18
+ return null;
13
19
  }
14
- return entry;
15
20
  }
16
21
  export const resolveConfig = async () => {
17
22
  const configPath = join(cwd, 'prebundle.config.mjs');
@@ -25,6 +30,9 @@ export function parseTasks(dependencies) {
25
30
  const importPath = join(cwd, DIST_DIR, depName);
26
31
  const distPath = join(cwd, DIST_DIR, depName);
27
32
  const depPath = findDepPath(depName);
33
+ if (!depPath) {
34
+ throw new Error(`Failed to resolve dependency: ${depName}`);
35
+ }
28
36
  const depEntry = require.resolve(depName, { paths: [cwd] });
29
37
  const info = {
30
38
  depName,
package/dist/prebundle.js CHANGED
@@ -26,18 +26,22 @@ async function emitDts(task, externals) {
26
26
  outputDefaultDts();
27
27
  return;
28
28
  }
29
+ const getTypes = (json) => json.types || json.typing || json.typings || null;
29
30
  const getInput = () => {
30
31
  const pkgPath = join(task.depPath, 'package.json');
31
32
  const pkgJson = fs.readJsonSync(pkgPath, 'utf-8');
32
- const types = pkgJson.types || pkgJson.typing || pkgJson.typings;
33
+ const types = getTypes(pkgJson);
33
34
  if (types) {
34
35
  return join(task.depPath, types);
35
36
  }
36
37
  const depTypesPath = findDepPath(`@types/${task.depName}`);
38
+ if (!depTypesPath) {
39
+ return null;
40
+ }
37
41
  const depTypesPkgPath = join(depTypesPath, 'package.json');
38
42
  if (fs.existsSync(depTypesPkgPath)) {
39
43
  const depTypesPkg = fs.readJsonSync(depTypesPkgPath, 'utf-8');
40
- return depTypesPkg.types || depTypesPkg.typing || depTypesPkg.typings;
44
+ return getTypes(depTypesPkg);
41
45
  }
42
46
  return null;
43
47
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prebundle",
3
- "version": "1.1.0-beta.3",
3
+ "version": "1.1.0-beta.4",
4
4
  "main": "./dist/index.js",
5
5
  "type": "module",
6
6
  "repository": {