Skip to content

Commit 689b451

Browse files
committed
fix: Revert "fix: package.json resolve"
This reverts commit b71bb25.
1 parent e30ee13 commit 689b451

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

template/javascript/build.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import path from 'node:path';
22
import process from 'node:process';
3+
import { fileURLToPath } from 'node:url';
34
import fs from 'fs-extra';
45
import chokidar from 'chokidar';
56
import babel from '@babel/core';
@@ -32,7 +33,7 @@ async function resolvePeer(module) {
3233

3334
try {
3435
const pkg = await fs.readJson(
35-
path.resolve('node_modules', module, 'package.json'),
36+
fileURLToPath(new URL(import.meta.resolve(`${module}/package.json`))),
3637
'utf8',
3738
);
3839
return pkg.peerDependencies;
@@ -96,18 +97,18 @@ function traverseAST(ast, babelOnly = false) {
9697
}
9798

9899
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`)),
103102
);
103+
const modulePath = path.dirname(pkgPath);
104+
const { miniprogram } = await fs.readJson(pkgPath, 'utf8');
104105

105106
let source = '';
106107
if (miniprogram) {
107-
source = path.join(libPath, miniprogram);
108+
source = path.join(modulePath, miniprogram);
108109
} else {
109110
try {
110-
const dist = path.join(libPath, 'miniprogram_dist');
111+
const dist = path.join(modulePath, 'miniprogram_dist');
111112
const stats = await fs.stat(dist);
112113
if (stats.isDirectory()) {
113114
source = dist;

template/typescript/build.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import path from 'node:path';
22
import process from 'node:process';
3+
import { fileURLToPath } from 'node:url';
34
import fs from 'fs-extra';
45
import chokidar from 'chokidar';
56
import babel from '@babel/core';
@@ -32,7 +33,7 @@ async function resolvePeer(module) {
3233

3334
try {
3435
const pkg = await fs.readJson(
35-
path.resolve('node_modules', module, 'package.json'),
36+
fileURLToPath(new URL(import.meta.resolve(`${module}/package.json`))),
3637
'utf8',
3738
);
3839
return pkg.peerDependencies;
@@ -96,18 +97,18 @@ function traverseAST(ast, babelOnly = false) {
9697
}
9798

9899
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`)),
103102
);
103+
const modulePath = path.dirname(pkgPath);
104+
const { miniprogram } = await fs.readJson(pkgPath, 'utf8');
104105

105106
let source = '';
106107
if (miniprogram) {
107-
source = path.join(libPath, miniprogram);
108+
source = path.join(modulePath, miniprogram);
108109
} else {
109110
try {
110-
const dist = path.join(libPath, 'miniprogram_dist');
111+
const dist = path.join(modulePath, 'miniprogram_dist');
111112
const stats = await fs.stat(dist);
112113
if (stats.isDirectory()) {
113114
source = dist;

0 commit comments

Comments
 (0)