Skip to content

Commit

Permalink
build: 根据nodejs的版本使用不同的方法加载json文件
Browse files Browse the repository at this point in the history
  • Loading branch information
duan602728596 committed Oct 10, 2024
1 parent c05460c commit a5ace17
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 4 deletions.
2 changes: 1 addition & 1 deletion scripts/clean.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { glob } from 'glob';
import fse from 'fs-extra';
import zip from 'cross-zip';
import { build, unpacked, isMacOS, isWindows, isArm64 } from './utils.mjs';
import lernaJson from '../lerna.json' assert { type: 'json' };
import { lernaJson } from './jsonImport/jsonImport.mjs';

const zipPromise = util.promisify(zip.zip);

Expand Down
9 changes: 9 additions & 0 deletions scripts/jsonImport/gteV22.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import packageJson from '../../package.json' with { type: 'json' };
import lernaJson from '../../lerna.json' with { type: 'json' };
import appPackageJson from '../../app/package.json' with { type: 'json' };

export {
packageJson,
lernaJson,
appPackageJson
};
17 changes: 17 additions & 0 deletions scripts/jsonImport/jsonImport.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import process from 'node:process';
import semver from 'semver';

/* 根据不同的nodejs版本加载不同的文件 */
let jsonImport;

if (semver.gte(process.version, '22.0.0')) {
jsonImport = await import('./gteV22.mjs');
} else {
jsonImport = await import('./ltV22.mjs');
}

export const {
packageJson,
lernaJson,
appPackageJson
} = jsonImport;
9 changes: 9 additions & 0 deletions scripts/jsonImport/ltV22.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import packageJson from '../../package.json' assert { type: 'json' };
import lernaJson from '../../lerna.json' assert { type: 'json' };
import appPackageJson from '../../app/package.json' assert { type: 'json' };

export {
packageJson,
lernaJson,
appPackageJson
};
4 changes: 2 additions & 2 deletions scripts/taskfile.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { merge } from 'webpack-merge';
import { requireJson } from '@sweet-milktea/utils';
import { require, appDir, webpackBuild, webpackNodeDefaultCjsBuildConfig } from './utils.mjs';
import { buildModules } from '../packages/esm-build/buildModules.mjs';
import packageJson from '../app/package.json' assert { type: 'json' };
import { appPackageJson } from './jsonImport/jsonImport.mjs';

const argv = process.argv.slice(2);

Expand Down Expand Up @@ -81,7 +81,7 @@ async function taskFile() {
await rimraf(appNodeModules);

// 创建目录和文件
for (const depName of Object.keys(packageJson.dependencies)) {
for (const depName of Object.keys(appPackageJson.dependencies)) {
if (!['node-nim'].includes(depName)) {
console.log(`正在编译模块:${ depName }...`);
await createFilesByDependenciesName(depName);
Expand Down
2 changes: 1 addition & 1 deletion scripts/unpack.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import builder from 'electron-builder';
import { cwd, appDir, wwwDir, staticsDir, build, sdkDownloadDir, output, unpacked, unpackedNodeModules, isMacOS, isArm64 } from './utils.mjs';
import taskfile from './taskfile.mjs';
import nimSdkDownload from './nimSdkDownload.mjs';
import packageJson from '../package.json' assert { type: 'json' };
import { packageJson } from './jsonImport/jsonImport.mjs';

const staticsFiles = {
LICENSE: path.join(cwd, 'LICENSE'), // 许可协议
Expand Down

0 comments on commit a5ace17

Please sign in to comment.