diff --git a/package.json b/package.json index e7ba719e3..10c769361 100644 --- a/package.json +++ b/package.json @@ -22,14 +22,16 @@ "scripts": { "lint": "tslint \"src/**/*.ts\" --project tsconfig.json", "lint-fix": "tslint \"src/**/*.ts\" --project tsconfig.json --fix", - "clean": "rimraf dist && rimraf tsconfig.schema.json && rimraf tsconfig.schemastore-schema.json", - "build": "npm run clean && npm run build-tsc && npm run build-configSchema", + "clean": "rimraf dist && rimraf tsconfig.schema.json && rimraf tsconfig.schemastore-schema.json && rimraf tests/ts-node-packed.tgz", + "build": "npm run build-nopack && npm run build-pack", + "build-nopack": "npm run clean && npm run build-tsc && npm run build-configSchema", "build-tsc": "tsc", "build-configSchema": "typescript-json-schema --topRef --refs --validationKeywords allOf --out tsconfig.schema.json tsconfig.json TsConfigSchema && node --require ./register ./scripts/create-merged-schema", + "build-pack": "node ./scripts/build-pack.js", "test-spec": "mocha dist/**/*.spec.js -R spec --bail", "test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- \"dist/**/*.spec.js\" -R spec --bail", "test": "npm run build && npm run lint && npm run test-cov", - "prepare": "npm run build" + "prepare": "npm run build-nopack" }, "engines": { "node": ">=6.0.0" diff --git a/scripts/build-pack.js b/scripts/build-pack.js new file mode 100644 index 000000000..38811e99c --- /dev/null +++ b/scripts/build-pack.js @@ -0,0 +1,20 @@ +// Written in JS to support Windows +// Would otherwise be written as inline bash in package.json script + +const { exec } = require('child_process') +const { mkdtempSync, writeFileSync, readFileSync, unlinkSync, rmdirSync, readdirSync } = require('fs') +const { join } = require('path') + +const testDir = join(__dirname, '../tests') +const tarballPath = join(testDir, 'ts-node-packed.tgz') +const tempDir = mkdtempSync(join(testDir, 'tmp')) +exec(`npm pack "${join(__dirname, '..')}"`, { cwd: tempDir }, (err, stdout) => { + if (err) { + console.error(err) + process.exit(1) + } + const tempTarballPath = join(tempDir, readdirSync(tempDir)[0]) + writeFileSync(tarballPath, readFileSync(tempTarballPath)) + unlinkSync(tempTarballPath) + rmdirSync(tempDir) +}) diff --git a/src/index.spec.ts b/src/index.spec.ts index 5a55ac1cb..fd4f12b59 100644 --- a/src/index.spec.ts +++ b/src/index.spec.ts @@ -10,9 +10,7 @@ import * as promisify from 'util.promisify' const execP = promisify(exec) -const ROOT_DIR = join(__dirname, '..') const TEST_DIR = join(__dirname, '../tests') -const TARBALL_PATH = join(TEST_DIR, 'ts-node-packed.tgz') const PROJECT = join(TEST_DIR, 'tsconfig.json') const BIN_PATH = join(TEST_DIR, 'node_modules/.bin/ts-node') const BIN_SCRIPT_PATH = join(TEST_DIR, 'node_modules/.bin/ts-node-script') @@ -22,12 +20,6 @@ const SOURCE_MAP_REGEXP = /\/\/# sourceMappingURL=data:application\/json;charset // Pack and install ts-node locally, necessary to test package "exports" before(async function () { this.timeout(30000) - const tempDir = mkdtempSync(join(TEST_DIR, 'tmp')) - await execP(`npm pack --ignore-scripts "${ROOT_DIR}"`, { cwd: tempDir }) - const tarballPath = join(tempDir, readdirSync(tempDir)[0]) - writeFileSync(TARBALL_PATH, readFileSync(tarballPath)) - unlinkSync(tarballPath) - rmdirSync(tempDir) await execP(`npm install`, { cwd: TEST_DIR }) const packageLockPath = join(TEST_DIR, 'package-lock.json') existsSync(packageLockPath) && unlinkSync(packageLockPath)