mirror of
https://github.com/tiddly-gittly/TidGi-Desktop.git
synced 2026-04-27 07:40:55 -07:00
fix: zx don't need npm install
This commit is contained in:
parent
13ea38620c
commit
f0cb56542d
1 changed files with 61 additions and 71 deletions
|
|
@ -12,10 +12,9 @@
|
|||
* Adapted for electron forge https://github.com/electron-userland/electron-forge/issues/2248
|
||||
*/
|
||||
const path = require('path');
|
||||
const fs = require('fs-extra');
|
||||
const util = require('util');
|
||||
const fs = require('fs');
|
||||
const packageJSON = require('../package.json');
|
||||
const exec = util.promisify(require('child_process').exec);
|
||||
const exec = require('child_process').execSync;
|
||||
|
||||
/**
|
||||
* Specific which lproj you want to keep
|
||||
|
|
@ -41,7 +40,7 @@ exports.default = async (
|
|||
// const appParentPath = path.resolve(buildPath, '..', '..', '..', '..');
|
||||
// const appPath = path.join(appParentPath, 'Electron.app');
|
||||
const shell = platform === 'darwin' ? '/bin/zsh' : undefined;
|
||||
const winMacLinuxPlatformName = platform === 'darwin' ? 'mac' : (platform === 'win32' ? 'win' : 'linux');
|
||||
// const winMacLinuxPlatformName = platform === 'darwin' ? 'mac' : (platform === 'win32' ? 'win' : 'linux');
|
||||
/** delete useless lproj files to make it clean */
|
||||
// const lproj = glob.sync('*.lproj', { cwd });
|
||||
const lproj = fs.readdirSync(cwd).filter((dir) => dir.endsWith('.lproj'));
|
||||
|
|
@ -53,42 +52,36 @@ exports.default = async (
|
|||
await fs.remove(dir);
|
||||
}));
|
||||
}
|
||||
/** copy npm packages with node-worker dependencies with binary (dugite) or __filename usages (tiddlywiki), which can't be prepare properly by webpack */
|
||||
const tasks = [];
|
||||
console.log(`copy npm packages with node-worker dependencies with binary (dugite) or __filename usages (tiddlywiki), which can't be prepare properly by webpack`);
|
||||
if (['production', 'test'].includes(process.env.NODE_ENV)) {
|
||||
console.log('Copying tiddlywiki dependency to dist');
|
||||
const sourceNodeModulesFolder = path.resolve(projectRoot, 'node_modules');
|
||||
tasks.push(
|
||||
fs
|
||||
.copy(
|
||||
path.join(sourceNodeModulesFolder, 'zx'),
|
||||
path.join(cwd, 'node_modules', 'zx'),
|
||||
{ dereference: true },
|
||||
)
|
||||
.then(async () => {
|
||||
// not using pnpm, because after using it, it always causing problem here, causing `Error: spawn /bin/sh ENOENT` in github actions
|
||||
// it can probably being "working directory didn't exist" in https://github.com/nodejs/node/issues/9644#issuecomment-282060923
|
||||
// await exec(`pnpm i --shamefully-hoist --prod --ignore-scripts`, { cwd: path.join(cwd, 'node_modules', 'zx'), shell });
|
||||
await exec(`npm i --legacy-building --omit=dev`, {
|
||||
cwd: path.join(cwd, 'node_modules', 'zx'),
|
||||
shell,
|
||||
});
|
||||
await exec(`npm i --legacy-building --omit=dev`, {
|
||||
cwd: path.join(cwd, 'node_modules', 'zx', 'node_modules', 'globby'),
|
||||
shell,
|
||||
});
|
||||
await exec(`npm i --legacy-building --omit=dev --ignore-scripts`, {
|
||||
cwd: path.join(
|
||||
cwd,
|
||||
'node_modules',
|
||||
'zx',
|
||||
'node_modules',
|
||||
'node-fetch',
|
||||
),
|
||||
shell,
|
||||
});
|
||||
}),
|
||||
fs.cpSync(
|
||||
path.join(sourceNodeModulesFolder, 'zx'),
|
||||
path.join(cwd, 'node_modules', 'zx'),
|
||||
{ dereference: true, recursive: true },
|
||||
);
|
||||
// not using pnpm, because after using it, it always causing problem here, causing `Error: spawn /bin/sh ENOENT` in github actions
|
||||
// it can probably being "working directory didn't exist" in https://github.com/nodejs/node/issues/9644#issuecomment-282060923
|
||||
// exec(`pnpm i --shamefully-hoist --prod --ignore-scripts`, { cwd: path.join(cwd, 'node_modules', 'zx'), shell });
|
||||
// exec(`npm i --legacy-building --omit=dev`, {
|
||||
// cwd: path.join(cwd, 'node_modules', 'zx'),
|
||||
// shell,
|
||||
// });
|
||||
// exec(`npm i --legacy-building --omit=dev`, {
|
||||
// cwd: path.join(cwd, 'node_modules', 'zx', 'node_modules', 'globby'),
|
||||
// shell,
|
||||
// });
|
||||
// exec(`npm i --legacy-building --omit=dev --ignore-scripts`, {
|
||||
// cwd: path.join(
|
||||
// cwd,
|
||||
// 'node_modules',
|
||||
// 'zx',
|
||||
// 'node_modules',
|
||||
// 'node-fetch',
|
||||
// ),
|
||||
// shell,
|
||||
// });
|
||||
const packagePathsToCopyDereferenced = [
|
||||
['@tiddlygit', 'tiddlywiki', 'package.json'],
|
||||
['@tiddlygit', 'tiddlywiki', 'boot'],
|
||||
|
|
@ -100,44 +93,42 @@ exports.default = async (
|
|||
// we only need its `main` binary, no need its dependency and code, because we already copy it to src/services/native/externalApp
|
||||
['app-path', 'main'],
|
||||
];
|
||||
|
||||
console.log(`Copying packagePathsToCopyDereferenced`);
|
||||
for (const packagePathInNodeModules of packagePathsToCopyDereferenced) {
|
||||
// some binary may not exist in other platforms, so allow failing here.
|
||||
tasks.push(
|
||||
fs
|
||||
.copy(
|
||||
path.resolve(sourceNodeModulesFolder, ...packagePathInNodeModules),
|
||||
path.resolve(cwd, 'node_modules', ...packagePathInNodeModules),
|
||||
{ dereference: true },
|
||||
)
|
||||
.catch((error) => {
|
||||
// some binary may not exist in other platforms, so allow failing here.
|
||||
console.error(
|
||||
`Error copying ${
|
||||
packagePathInNodeModules.join(
|
||||
'/',
|
||||
)
|
||||
} to dist, in afterPack.js, Error: ${error.message}`,
|
||||
);
|
||||
}),
|
||||
);
|
||||
try {
|
||||
fs.cpSync(
|
||||
path.resolve(sourceNodeModulesFolder, ...packagePathInNodeModules),
|
||||
path.resolve(cwd, 'node_modules', ...packagePathInNodeModules),
|
||||
{ dereference: true, recursive: true },
|
||||
);
|
||||
} catch (error) {
|
||||
// some binary may not exist in other platforms, so allow failing here.
|
||||
console.error(
|
||||
`Error copying ${
|
||||
packagePathInNodeModules.join(
|
||||
'/',
|
||||
)
|
||||
} to dist, in afterPack.js, Error: ${error.message}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
// it has things like `git/bin/libexec/git-core/git-add` link to `git/bin/libexec/git-core/git`, to reduce size, so can't use `dereference: true` here.
|
||||
console.log('Copy dugite');
|
||||
// it has things like `git/bin/libexec/git-core/git-add` link to `git/bin/libexec/git-core/git`, to reduce size, so can't use `dereference: true, recursive: true` here.
|
||||
// And pnpm will have node_modules/dugite to be a shortcut, can't just copy it with `dereference: false`, have to copy from .pnpm folder
|
||||
tasks.push(
|
||||
fs.copy(
|
||||
path.join(
|
||||
sourceNodeModulesFolder,
|
||||
'.pnpm',
|
||||
`dugite@${packageJSON.dependencies.dugite}`,
|
||||
'node_modules',
|
||||
'dugite',
|
||||
),
|
||||
path.join(cwd, 'node_modules', 'dugite'),
|
||||
{
|
||||
dereference: false,
|
||||
},
|
||||
fs.cpSync(
|
||||
path.join(
|
||||
sourceNodeModulesFolder,
|
||||
'.pnpm',
|
||||
`dugite@${packageJSON.dependencies.dugite}`,
|
||||
'node_modules',
|
||||
'dugite',
|
||||
),
|
||||
path.join(cwd, 'node_modules', 'dugite'),
|
||||
{
|
||||
dereference: false,
|
||||
recursive: true,
|
||||
},
|
||||
);
|
||||
}
|
||||
/** sign it for mac m1 https://www.zhihu.com/question/431722091/answer/1592339574 (only work if user run this.)
|
||||
|
|
@ -149,9 +140,8 @@ exports.default = async (
|
|||
```
|
||||
*/
|
||||
// if (platform === 'darwin') {
|
||||
// await exec(`xattr -rd com.apple.quarantine ${appPath}`, { cwd: appParentPath, shell });
|
||||
// exec(`xattr -rd com.apple.quarantine ${appPath}`, { cwd: appParentPath, shell });
|
||||
// }
|
||||
await Promise.all(tasks);
|
||||
/** complete this hook */
|
||||
callback();
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue