Skip to content

Commit

Permalink
fix: ignore ets when the current app don't has a framework dependenci…
Browse files Browse the repository at this point in the history
…es (#213)
  • Loading branch information
fengmk2 committed Jan 30, 2023
1 parent b6f74de commit 666a342
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 8 deletions.
5 changes: 4 additions & 1 deletion bin/postinstall.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ const path = require('path');
const fs = require('fs');
const runscript = require('runscript');

// node posintall.js </path/to/egg-ts-helper/dist/bin>
// node posintall.js </path/to/egg-ts-helper/dist/bin> <framework-package-name>
const etsBinFile = process.argv[2] || require.resolve('egg-ts-helper/dist/bin');
const frameworkPackageName = process.argv[3] || 'egg';

// try to use INIT_CWD env https://docs.npmjs.com/cli/v9/commands/npm-run-script
// npm_rootpath is npminstall
Expand All @@ -23,6 +24,8 @@ if (npmRunRoot) {
// }
if (pkg.eggModule) return;
if (pkg.egg.isFramework) return;
// ignore when the current app don't has a framework dependencies
if (!pkg.dependencies || !pkg.dependencies[frameworkPackageName]) return;
// set ETS_CWD
process.env.ETS_CWD = npmRunRoot;
console.log('[egg-bin:postinstall] run %s on %s', etsBinFile, npmRunRoot);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"coffee": "^5.4.0",
"cross-env": "^3.1.3",
"egg": "^3.9.1",
"egg-mock": "^5.8.3",
"egg-mock": "^5.10.2",
"esbuild-register": "^2.5.0",
"eslint": "^8.16.0",
"eslint-config-egg": "^12.0.0",
Expand Down
17 changes: 17 additions & 0 deletions test/ets-bin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,21 @@ describe('test/ets-bin.test.js', () => {
.expect('code', 0)
.end();
});

it('should test with postinstall ignore when missing egg deps', async () => {
const cwd = path.join(__dirname, 'fixtures/example-missing-egg-deps-ets');
await coffee.spawn('node', [ postinstallScript ], {
cwd,
env: {
...process.env,
ETS_SILENT: 'false',
INIT_CWD: cwd,
},
})
.debug()
.notExpect('stdout', /\[egg-ts-helper\] create/)
.notExpect('stdout', /\[egg-bin:postinstall] run /)
.expect('code', 0)
.end();
});
});
3 changes: 0 additions & 3 deletions test/fixtures/example-egg-framework-ets/package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
{
"name": "example-egg-framework-ets",
"eggModule": {
"name": "foo"
},
"egg": {
"typescript": true,
"isFramework": true
Expand Down
7 changes: 7 additions & 0 deletions test/fixtures/example-missing-egg-deps-ets/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "example-missing-egg-deps-ets",
"egg": {
"typescript": true
},
"dependencies": {}
}
5 changes: 4 additions & 1 deletion test/fixtures/example-ts-ets/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@
"egg": {
"typescript": true,
"declarations": false
},
"dependencies": {
"egg": "*"
}
}
}
2 changes: 0 additions & 2 deletions test/fixtures/test-demo-app/test/a.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use strict';

const { app } = require('egg-mock/bootstrap');

describe('a.test.js', () => {
Expand Down

0 comments on commit 666a342

Please sign in to comment.