prebundle 1.1.0-beta.2 → 1.1.0-beta.3

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 (2) hide show
  1. package/dist/prebundle.js +19 -16
  2. package/package.json +1 -1
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,29 @@ 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 getInput = () => {
30
+ const pkgPath = join(task.depPath, 'package.json');
31
+ const pkgJson = fs.readJsonSync(pkgPath, 'utf-8');
32
+ const types = pkgJson.types || pkgJson.typing || pkgJson.typings;
33
+ if (types) {
34
+ return join(task.depPath, types);
35
+ }
36
+ const depTypesPath = findDepPath(`@types/${task.depName}`);
37
+ const depTypesPkgPath = join(depTypesPath, 'package.json');
38
+ if (fs.existsSync(depTypesPkgPath)) {
39
+ const depTypesPkg = fs.readJsonSync(depTypesPkgPath, 'utf-8');
40
+ return depTypesPkg.types || depTypesPkg.typing || depTypesPkg.typings;
41
+ }
42
+ return null;
43
+ };
44
+ const input = getInput();
45
+ if (!input) {
43
46
  outputDefaultDts();
44
47
  return;
45
48
  }
46
49
  try {
47
50
  const inputConfig = {
48
- input: join(task.depPath, types),
51
+ input,
49
52
  external: Object.keys(externals),
50
53
  plugins: [
51
54
  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.3",
4
4
  "main": "./dist/index.js",
5
5
  "type": "module",
6
6
  "repository": {