prebundle 1.1.0-beta.3 → 1.1.0-beta.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/README.md +1 -1
- package/dist/helper.d.ts +1 -1
- package/dist/helper.js +16 -7
- package/dist/prebundle.js +9 -8
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Prebundle 3rd party dependencies, output a single js file, a package.json file and the dts files.
|
|
4
4
|
|
|
5
|
-
Based on [ncc](https://github.com/vercel/ncc) and
|
|
5
|
+
Based on [ncc](https://github.com/vercel/ncc) and [rollup-plugin-dts](https://www.npmjs.com/package/rollup-plugin-dts).
|
|
6
6
|
|
|
7
7
|
<p>
|
|
8
8
|
<a href="https://npmjs.com/package/prebundle">
|
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
|
@@ -2,20 +2,26 @@ import { dirname, join } from 'node:path';
|
|
|
2
2
|
import fs from '../compiled/fs-extra/index.js';
|
|
3
3
|
import { cwd, DIST_DIR } from './constant.js';
|
|
4
4
|
import { createRequire } from 'node:module';
|
|
5
|
+
import { pathToFileURL } from 'node:url';
|
|
5
6
|
const require = createRequire(import.meta.url);
|
|
6
7
|
export function findDepPath(name) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
try {
|
|
9
|
+
let entry = dirname(require.resolve(join(name), { paths: [cwd] }));
|
|
10
|
+
while (!dirname(entry).endsWith('node_modules')) {
|
|
11
|
+
entry = dirname(entry);
|
|
12
|
+
}
|
|
13
|
+
if (name.includes('/')) {
|
|
14
|
+
return join(dirname(entry), name);
|
|
15
|
+
}
|
|
16
|
+
return entry;
|
|
10
17
|
}
|
|
11
|
-
|
|
12
|
-
return
|
|
18
|
+
catch (err) {
|
|
19
|
+
return null;
|
|
13
20
|
}
|
|
14
|
-
return entry;
|
|
15
21
|
}
|
|
16
22
|
export const resolveConfig = async () => {
|
|
17
23
|
const configPath = join(cwd, 'prebundle.config.mjs');
|
|
18
|
-
const config = await import(configPath);
|
|
24
|
+
const config = await import(pathToFileURL(configPath).href);
|
|
19
25
|
return config.default;
|
|
20
26
|
};
|
|
21
27
|
export function parseTasks(dependencies) {
|
|
@@ -25,6 +31,9 @@ export function parseTasks(dependencies) {
|
|
|
25
31
|
const importPath = join(cwd, DIST_DIR, depName);
|
|
26
32
|
const distPath = join(cwd, DIST_DIR, depName);
|
|
27
33
|
const depPath = findDepPath(depName);
|
|
34
|
+
if (!depPath) {
|
|
35
|
+
throw new Error(`Failed to resolve dependency: ${depName}`);
|
|
36
|
+
}
|
|
28
37
|
const depEntry = require.resolve(depName, { paths: [cwd] });
|
|
29
38
|
const info = {
|
|
30
39
|
depName,
|
package/dist/prebundle.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { join } from 'node:path';
|
|
1
|
+
import { dirname, join } from 'node:path';
|
|
2
2
|
import ncc from '@vercel/ncc';
|
|
3
3
|
import fastGlob from '../compiled/fast-glob/index.js';
|
|
4
4
|
import fs from '../compiled/fs-extra/index.js';
|
|
@@ -26,20 +26,21 @@ 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
|
|
33
|
+
const types = getTypes(pkgJson);
|
|
33
34
|
if (types) {
|
|
34
35
|
return join(task.depPath, types);
|
|
35
36
|
}
|
|
36
|
-
const depTypesPath = findDepPath(`@types/${task.depName}`);
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
const depTypesPkg = fs.readJsonSync(depTypesPkgPath, 'utf-8');
|
|
40
|
-
return depTypesPkg.types || depTypesPkg.typing || depTypesPkg.typings;
|
|
37
|
+
const depTypesPath = findDepPath(`@types/${task.depName}/package.json`);
|
|
38
|
+
if (!depTypesPath) {
|
|
39
|
+
return null;
|
|
41
40
|
}
|
|
42
|
-
|
|
41
|
+
const depTypesPkg = fs.readJsonSync(depTypesPath, 'utf-8');
|
|
42
|
+
const depTypes = getTypes(depTypesPkg);
|
|
43
|
+
return depTypes ? join(dirname(depTypesPath), depTypes) : null;
|
|
43
44
|
};
|
|
44
45
|
const input = getInput();
|
|
45
46
|
if (!input) {
|