Skip to content

Commit

Permalink
fix: add scripts dir to exclude (#219)
Browse files Browse the repository at this point in the history
closes #218
  • Loading branch information
fengmk2 authored Feb 14, 2023
1 parent 0b987d4 commit 0fb74f7
Show file tree
Hide file tree
Showing 12 changed files with 25 additions and 26 deletions.
2 changes: 0 additions & 2 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
node_modules/
coverage/
scripts/
*.js
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
"eslint": "^8.16.0",
"eslint-config-egg": "^12.0.0",
"git-contributor": "2",
"mm": "^3.2.0",
"typescript": "^4.9.5"
},
"repository": {
Expand All @@ -65,15 +64,15 @@
"homepage": "https://github.com/eggjs/egg-bin",
"author": "fengmk2 <fengmk2@gmail.com> (https://github.com/fengmk2)",
"scripts": {
"postinstall": "node scripts/postinstall",
"postinstall": "node scripts/postinstall.js",
"contributor": "git-contributor",
"lint": "eslint . --cache --ext ts",
"test": "npm run lint -- --fix && npm run test-local",
"test-local": "ts-node --swc src/bin/cli.ts test",
"test-local-with-ts-node-transpile-only": "node -r ts-node/register/transpile-only src/bin/cli.ts test",
"test-local-with-swc": "node -r @swc-node/register src/bin/cli.ts test",
"test-local-with-esbuild": "node -r esbuild-register src/bin/cli.ts test",
"test-tsc": "npm run clean && npm run tsc && rm -rf src && node dist/bin/cli.js && node dist/bin/cli.js test --base test/fixtures/example-ts",
"test-tsc": "npm run clean && npm run tsc && node dist/bin/cli.js && node dist/bin/cli.js test --base test/fixtures/example-ts && node dist/bin/cli.js dev --base test/fixtures/example-ts",
"cov": "c8 -r lcov -r text-summary -x 'test/**' npm run test-local -- --timeout 120000",
"ci-test-only": "npm run test-local -- test/cmd/cov.test.ts",
"ci": "npm run lint && npm run cov && npm run test-tsc",
Expand Down
4 changes: 4 additions & 0 deletions scripts/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"root": true,
"extends": "eslint-config-egg"
}
11 changes: 9 additions & 2 deletions scripts/postinstall → scripts/postinstall.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env node

const debug = require('node:util').debuglog('egg-bin:postinstall');
const path = require('node:path');
const fs = require('node:fs');
const runscript = require('runscript');
Expand All @@ -11,6 +10,14 @@ 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
const npmRunRoot = process.env.INIT_CWD || process.env.npm_rootpath;

debug('process.argv: %o', process.argv);
debug('process.env.INIT_CWD: %o', process.env.INIT_CWD);
debug('process.env.npm_rootpath: %o', process.env.npm_rootpath);
debug('etsBinFile: %o', etsBinFile);
debug('frameworkPackageName: %o', frameworkPackageName);
debug('npmRunRoot: %o', npmRunRoot);

if (npmRunRoot) {
const pkgFile = path.join(npmRunRoot, 'package.json');
if (fs.existsSync(pkgFile)) {
Expand Down
2 changes: 0 additions & 2 deletions scripts/start-cluster → scripts/start-cluster.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#!/usr/bin/env node

const debug = require('util').debuglog('egg-bin:lib:start-cluster');

debug('argv: %o', process.argv);
Expand Down
10 changes: 9 additions & 1 deletion src/bin/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,12 @@

import { start } from '@artus-cli/artus-cli';

start();
const isBuildJavascriptFile = __filename.endsWith('.js');
const exclude = [ 'scripts', 'bin', 'test', 'coverage' ];
if (isBuildJavascriptFile) {
exclude.push('*.ts');
} else {
exclude.push('dist');
}

start({ exclude });
2 changes: 1 addition & 1 deletion src/cmd/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class DevCommand extends BaseCommand {
debug('run dev: %o', this.args);
this.ctx.env.NODE_ENV = this.ctx.env.NODE_ENV ?? 'development';
this.ctx.env.EGG_MASTER_CLOSE_TIMEOUT = '1000';
const serverBin = path.join(__dirname, '../../scripts/start-cluster');
const serverBin = path.join(__dirname, '../../scripts/start-cluster.js');
const args = await this.formatEggStartArgs();
const serverCmd = `${serverBin} '${JSON.stringify(args)}'`;
const requires = await this.formatRequires();
Expand Down
3 changes: 0 additions & 3 deletions test/cmd/cov.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import assert from 'node:assert';
import path from 'node:path';
import fs from 'node:fs/promises';
import mm from 'mm';
import assertFile from 'assert-file';
import coffee from '../coffee';

Expand All @@ -17,8 +16,6 @@ describe('test/cmd/cov.test.ts', () => {
assertFile(path.join(baseDir, 'coverage/lcov.info'));
}

afterEach(mm.restore);

describe('egg-bin cov', () => {
it('should success on js', async () => {
await coffee.fork(eggBin, [ 'cov', '--ts=false' ], { cwd, env: { TESTS: 'test/**/*.test.js' } })
Expand Down
3 changes: 0 additions & 3 deletions test/cmd/debug.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import path from 'node:path';
import mm from 'mm';
import coffee from '../coffee';

describe('test/cmd/debug.test.ts', () => {
const eggBin = path.join(__dirname, '../../src/bin/cli.ts');
const fixtures = path.join(__dirname, '../fixtures');
const cwd = path.join(fixtures, 'demo-app');

afterEach(mm.restore);

it('should startCluster success', () => {
return coffee.fork(eggBin, [ 'debug' ], { cwd })
// .debug()
Expand Down
3 changes: 0 additions & 3 deletions test/cmd/dev.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import path from 'node:path';
import net from 'node:net';
import mm from 'mm';
import detect from 'detect-port';
import coffee from '../coffee';

Expand All @@ -9,8 +8,6 @@ describe('test/cmd/dev.test.ts', () => {
const fixtures = path.join(__dirname, '../fixtures');
const cwd = path.join(fixtures, 'demo-app');

afterEach(mm.restore);

it('should startCluster success', () => {
return coffee.fork(eggBin, [ 'dev' ], { cwd })
// .debug()
Expand Down
3 changes: 0 additions & 3 deletions test/cmd/test.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import path from 'node:path';
import mm from 'mm';
import coffee from '../coffee';

describe('test/cmd/test.test.ts', () => {
const eggBin = path.join(__dirname, '../../src/bin/cli.ts');
const fixtures = path.join(__dirname, '../fixtures');
const cwd = path.join(fixtures, 'test-files');

afterEach(mm.restore);

describe('egg-bin test', () => {
it('should success js', () => {
return coffee.fork(eggBin, [ 'test' ], { cwd })
Expand Down
3 changes: 0 additions & 3 deletions test/ts.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import assert from 'node:assert';
import path from 'node:path';
import fs from 'node:fs/promises';
import mm from 'mm';
import runscript from 'runscript';
import coffee from './coffee';

Expand All @@ -14,8 +13,6 @@ describe('test/ts.test.ts', () => {
const fixtures = path.join(__dirname, 'fixtures');
let cwd: string;

afterEach(mm.restore);

it('should support ts', () => {
cwd = path.join(fixtures, 'ts');
return coffee.fork(eggBin, [ 'dev' ], { cwd, env: { NODE_ENV: 'development' } })
Expand Down

0 comments on commit 0fb74f7

Please sign in to comment.