prebundle 1.1.0-beta.2 → 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
@@ -4,7 +4,7 @@ import fastGlob from '../compiled/fast-glob/index.js';
4
4
  import fs from '../compiled/fs-extra/index.js';
5
5
  import rslog from '../compiled/rslog/index.js';
6
6
  import { DEFAULT_EXTERNALS } from './constant.js';
7
- import { pick, replaceFileContent } from './helper.js';
7
+ import { findDepPath, pick } from './helper.js';
8
8
  import { dts } from 'rollup-plugin-dts';
9
9
  import { rollup } from 'rollup';
10
10
  const { logger } = rslog;
@@ -18,16 +18,6 @@ function emitIndex(code, distPath) {
18
18
  const distIndex = join(distPath, 'index.js');
19
19
  fs.outputFileSync(distIndex, code);
20
20
  }
21
- function fixTypeExternalPath(file, task, externals) {
22
- const filepath = join(task.distPath, file);
23
- replaceFileContent(filepath, (content) => {
24
- let newContent = content;
25
- for (const name of Object.keys(externals)) {
26
- newContent = newContent.replace(new RegExp(`../../${name}`, 'g'), externals[name]);
27
- }
28
- return newContent;
29
- });
30
- }
31
21
  async function emitDts(task, externals) {
32
22
  const outputDefaultDts = () => {
33
23
  fs.writeFileSync(join(task.distPath, 'index.d.ts'), 'export = any;\n');
@@ -36,16 +26,33 @@ async function emitDts(task, externals) {
36
26
  outputDefaultDts();
37
27
  return;
38
28
  }
39
- const pkgPath = join(task.depPath, 'package.json');
40
- const pkgJson = fs.readJsonSync(pkgPath, 'utf-8');
41
- const types = pkgJson.types || pkgJson.typing || pkgJson.typings;
42
- if (!types) {
29
+ const getTypes = (json) => json.types || json.typing || json.typings || null;
30
+ const getInput = () => {
31
+ const pkgPath = join(task.depPath, 'package.json');
32
+ const pkgJson = fs.readJsonSync(pkgPath, 'utf-8');
33
+ const types = getTypes(pkgJson);
34
+ if (types) {
35
+ return join(task.depPath, types);
36
+ }
37
+ const depTypesPath = findDepPath(`@types/${task.depName}`);
38
+ if (!depTypesPath) {
39
+ return null;
40
+ }
41
+ const depTypesPkgPath = join(depTypesPath, 'package.json');
42
+ if (fs.existsSync(depTypesPkgPath)) {
43
+ const depTypesPkg = fs.readJsonSync(depTypesPkgPath, 'utf-8');
44
+ return getTypes(depTypesPkg);
45
+ }
46
+ return null;
47
+ };
48
+ const input = getInput();
49
+ if (!input) {
43
50
  outputDefaultDts();
44
51
  return;
45
52
  }
46
53
  try {
47
54
  const inputConfig = {
48
- input: join(task.depPath, types),
55
+ input,
49
56
  external: Object.keys(externals),
50
57
  plugins: [
51
58
  dts({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prebundle",
3
- "version": "1.1.0-beta.2",
3
+ "version": "1.1.0-beta.4",
4
4
  "main": "./dist/index.js",
5
5
  "type": "module",
6
6
  "repository": {