Skip to content

Commit b71bb25

Browse files
committed
fix: package.json resolve
close #16
1 parent bfad544 commit b71bb25

File tree

2 files changed

+14
-16
lines changed

2 files changed

+14
-16
lines changed

template/javascript/build.js

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

3433
try {
3534
const pkg = await fs.readJson(
36-
fileURLToPath(new URL(import.meta.resolve(`${module}/package.json`))),
35+
path.resolve('node_modules', module, 'package.json'),
3736
'utf8',
3837
);
3938
return pkg.peerDependencies;
@@ -97,18 +96,18 @@ function traverseAST(ast, babelOnly = false) {
9796
}
9897

9998
async function buildComponentLibrary(name) {
100-
const pkgPath = fileURLToPath(
101-
new URL(import.meta.resolve(`${name}/package.json`)),
99+
const libPath = path.resolve('node_modules', name);
100+
const { miniprogram } = await fs.readJson(
101+
path.join(libPath, 'package.json'),
102+
'utf8',
102103
);
103-
const modulePath = path.dirname(pkgPath);
104-
const { miniprogram } = await fs.readJson(pkgPath, 'utf8');
105104

106105
let source = '';
107106
if (miniprogram) {
108-
source = path.join(modulePath, miniprogram);
107+
source = path.join(libPath, miniprogram);
109108
} else {
110109
try {
111-
const dist = path.join(modulePath, 'miniprogram_dist');
110+
const dist = path.join(libPath, 'miniprogram_dist');
112111
const stats = await fs.stat(dist);
113112
if (stats.isDirectory()) {
114113
source = dist;

template/typescript/build.js

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

3433
try {
3534
const pkg = await fs.readJson(
36-
fileURLToPath(new URL(import.meta.resolve(`${module}/package.json`))),
35+
path.resolve('node_modules', module, 'package.json'),
3736
'utf8',
3837
);
3938
return pkg.peerDependencies;
@@ -97,18 +96,18 @@ function traverseAST(ast, babelOnly = false) {
9796
}
9897

9998
async function buildComponentLibrary(name) {
100-
const pkgPath = fileURLToPath(
101-
new URL(import.meta.resolve(`${name}/package.json`)),
99+
const libPath = path.resolve('node_modules', name);
100+
const { miniprogram } = await fs.readJson(
101+
path.join(libPath, 'package.json'),
102+
'utf8',
102103
);
103-
const modulePath = path.dirname(pkgPath);
104-
const { miniprogram } = await fs.readJson(pkgPath, 'utf8');
105104

106105
let source = '';
107106
if (miniprogram) {
108-
source = path.join(modulePath, miniprogram);
107+
source = path.join(libPath, miniprogram);
109108
} else {
110109
try {
111-
const dist = path.join(modulePath, 'miniprogram_dist');
110+
const dist = path.join(libPath, 'miniprogram_dist');
112111
const stats = await fs.stat(dist);
113112
if (stats.isDirectory()) {
114113
source = dist;

0 commit comments

Comments
 (0)