Skip to content

Commit

Permalink
move npm pack into build step
Browse files Browse the repository at this point in the history
  • Loading branch information
cspotcode committed May 10, 2020
1 parent 2869699 commit 40e16b6
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 11 deletions.
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
20 changes: 20 additions & 0 deletions scripts/build-pack.js
Original file line number Diff line number Diff line change
@@ -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)
})
8 changes: 0 additions & 8 deletions src/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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)
Expand Down

0 comments on commit 40e16b6

Please sign in to comment.