Skip to content

Commit

Permalink
fix: package.json resolve
Browse files Browse the repository at this point in the history
close #16
  • Loading branch information
yangmingshan committed Aug 7, 2024
1 parent bfad544 commit b71bb25
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
15 changes: 7 additions & 8 deletions template/javascript/build.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import path from 'node:path';
import process from 'node:process';
import { fileURLToPath } from 'node:url';
import fs from 'fs-extra';
import chokidar from 'chokidar';
import babel from '@babel/core';
Expand Down Expand Up @@ -33,7 +32,7 @@ async function resolvePeer(module) {

try {
const pkg = await fs.readJson(
fileURLToPath(new URL(import.meta.resolve(`${module}/package.json`))),
path.resolve('node_modules', module, 'package.json'),
'utf8',
);
return pkg.peerDependencies;
Expand Down Expand Up @@ -97,18 +96,18 @@ function traverseAST(ast, babelOnly = false) {
}

async function buildComponentLibrary(name) {
const pkgPath = fileURLToPath(
new URL(import.meta.resolve(`${name}/package.json`)),
const libPath = path.resolve('node_modules', name);
const { miniprogram } = await fs.readJson(
path.join(libPath, 'package.json'),
'utf8',
);
const modulePath = path.dirname(pkgPath);
const { miniprogram } = await fs.readJson(pkgPath, 'utf8');

let source = '';
if (miniprogram) {
source = path.join(modulePath, miniprogram);
source = path.join(libPath, miniprogram);
} else {
try {
const dist = path.join(modulePath, 'miniprogram_dist');
const dist = path.join(libPath, 'miniprogram_dist');
const stats = await fs.stat(dist);
if (stats.isDirectory()) {
source = dist;
Expand Down
15 changes: 7 additions & 8 deletions template/typescript/build.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import path from 'node:path';
import process from 'node:process';
import { fileURLToPath } from 'node:url';
import fs from 'fs-extra';
import chokidar from 'chokidar';
import babel from '@babel/core';
Expand Down Expand Up @@ -33,7 +32,7 @@ async function resolvePeer(module) {

try {
const pkg = await fs.readJson(
fileURLToPath(new URL(import.meta.resolve(`${module}/package.json`))),
path.resolve('node_modules', module, 'package.json'),
'utf8',
);
return pkg.peerDependencies;
Expand Down Expand Up @@ -97,18 +96,18 @@ function traverseAST(ast, babelOnly = false) {
}

async function buildComponentLibrary(name) {
const pkgPath = fileURLToPath(
new URL(import.meta.resolve(`${name}/package.json`)),
const libPath = path.resolve('node_modules', name);
const { miniprogram } = await fs.readJson(
path.join(libPath, 'package.json'),
'utf8',
);
const modulePath = path.dirname(pkgPath);
const { miniprogram } = await fs.readJson(pkgPath, 'utf8');

let source = '';
if (miniprogram) {
source = path.join(modulePath, miniprogram);
source = path.join(libPath, miniprogram);
} else {
try {
const dist = path.join(modulePath, 'miniprogram_dist');
const dist = path.join(libPath, 'miniprogram_dist');
const stats = await fs.stat(dist);
if (stats.isDirectory()) {
source = dist;
Expand Down

0 comments on commit b71bb25

Please sign in to comment.