|
1 | 1 | import path from 'node:path';
|
2 | 2 | import process from 'node:process';
|
| 3 | +import { fileURLToPath } from 'node:url'; |
3 | 4 | import fs from 'fs-extra';
|
4 | 5 | import chokidar from 'chokidar';
|
5 | 6 | import babel from '@babel/core';
|
@@ -32,7 +33,7 @@ async function resolvePeer(module) {
|
32 | 33 |
|
33 | 34 | try {
|
34 | 35 | const pkg = await fs.readJson(
|
35 |
| - path.resolve('node_modules', module, 'package.json'), |
| 36 | + fileURLToPath(new URL(import.meta.resolve(`${module}/package.json`))), |
36 | 37 | 'utf8',
|
37 | 38 | );
|
38 | 39 | return pkg.peerDependencies;
|
@@ -96,18 +97,18 @@ function traverseAST(ast, babelOnly = false) {
|
96 | 97 | }
|
97 | 98 |
|
98 | 99 | async function buildComponentLibrary(name) {
|
99 |
| - const libPath = path.resolve('node_modules', name); |
100 |
| - const { miniprogram } = await fs.readJson( |
101 |
| - path.join(libPath, 'package.json'), |
102 |
| - 'utf8', |
| 100 | + const pkgPath = fileURLToPath( |
| 101 | + new URL(import.meta.resolve(`${name}/package.json`)), |
103 | 102 | );
|
| 103 | + const modulePath = path.dirname(pkgPath); |
| 104 | + const { miniprogram } = await fs.readJson(pkgPath, 'utf8'); |
104 | 105 |
|
105 | 106 | let source = '';
|
106 | 107 | if (miniprogram) {
|
107 |
| - source = path.join(libPath, miniprogram); |
| 108 | + source = path.join(modulePath, miniprogram); |
108 | 109 | } else {
|
109 | 110 | try {
|
110 |
| - const dist = path.join(libPath, 'miniprogram_dist'); |
| 111 | + const dist = path.join(modulePath, 'miniprogram_dist'); |
111 | 112 | const stats = await fs.stat(dist);
|
112 | 113 | if (stats.isDirectory()) {
|
113 | 114 | source = dist;
|
|
0 commit comments