Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into ab/support-node-10-…
Browse files Browse the repository at this point in the history
…and-up
  • Loading branch information
cspotcode committed May 16, 2020
2 parents 2f5c13b + 5f305ea commit 61b75c5
Show file tree
Hide file tree
Showing 15 changed files with 274 additions and 74 deletions.
42 changes: 35 additions & 7 deletions .github/workflows/continuous-integration.yml
@@ -1,19 +1,44 @@
name: Continuous Integration
on:
# branches pushed by collaborators
push: {}
push:
branches:
- master
# pull request from non-collaborators
pull_request: {}
# nightly
schedule:
- cron: '0 0 * * *'
jobs:
test:
name: "Test #${{ matrix.flavor }}: node v${{ matrix.node }}, ${{ matrix.typescript }}"
lint-build:
name: "Lint & Build"
runs-on: ubuntu-latest
steps:
# checkout code
- uses: actions/checkout@v2
# install node
- name: Use Node.js 14
uses: actions/setup-node@v1
with:
node-version: 14
# lint, build, test
- run: npm install
- run: npm run lint
- run: npm run build
- name: Upload package artifact
uses: actions/upload-artifact@v1
with:
name: ts-node-packed.tgz
path: tests/ts-node-packed.tgz

test:
needs: lint-build
name: "Test #${{ matrix.flavor }}: ${{ matrix.os }}, node v${{ matrix.node }}, ${{ matrix.typescript }}"
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest]
flavor: [1, 2, 3, 4, 5, 6, 7, 8]
include:
- flavor: 1
Expand Down Expand Up @@ -50,17 +75,20 @@ jobs:
node-version: ${{ matrix.node }}
# lint, build, test
- run: npm install
- run: npm run lint
- run: npm run build
- run: npm rm tslint
- run: npm run build-nopack
- name: Download package artifact
uses: actions/download-artifact@v1
with:
name: ts-node-packed.tgz
path: tests/
- run: npm install ${{ matrix.typescript }} --force
- run: npm run test-cov
- name: Coveralls
if: ${{ always() }}
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.github_token }}
flag-name: run-${{ matrix.flavor }}
flag-name: run-${{ matrix.os }}-${{ matrix.flavor }}
parallel: true
finish:
needs: test
Expand Down
12 changes: 12 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 7 additions & 4 deletions package.json
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": ">=10.0.0"
Expand Down Expand Up @@ -77,7 +79,8 @@
"tslint": "^6.1.0",
"tslint-config-standard": "^9.0.0",
"typescript": "3.8.3",
"typescript-json-schema": "^0.42.0"
"typescript-json-schema": "^0.42.0",
"util.promisify": "^1.0.1"
},
"peerDependencies": {
"typescript": ">=2.7"
Expand Down
20 changes: 20 additions & 0 deletions 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)
})
26 changes: 9 additions & 17 deletions src/esm.ts
@@ -1,6 +1,6 @@
import { register, getExtensions, RegisterOptions } from './index'
import { parse as parseUrl, format as formatUrl, UrlWithStringQuery } from 'url'
import { posix as posixPath } from 'path'
import { parse as parseUrl, format as formatUrl, UrlWithStringQuery, fileURLToPath, pathToFileURL } from 'url'
import { extname } from 'path'
import * as assert from 'assert'
const { createResolve } = require('../dist-raw/node-esm-resolve-implementation')

Expand Down Expand Up @@ -65,13 +65,12 @@ export function registerAndCreateEsmHooks (opts?: RegisterOptions) {
const { pathname } = parsed
assert(pathname !== null, 'ESM getFormat() hook: URL should never have null pathname')

const nativePath = fileURLToPath(url)

// If file has .ts, .tsx, or .jsx extension, then ask node how it would treat this file if it were .js
const ext = posixPath.extname(pathname)
const ext = extname(nativePath)
if (ext === '.ts' || ext === '.tsx' || ext === '.jsx') {
return defer(formatUrl({
...parsed,
pathname: pathname + '.js'
}))
return defer(formatUrl(pathToFileURL(nativePath + '.js')))
}

return defer()
Expand All @@ -88,20 +87,13 @@ export function registerAndCreateEsmHooks (opts?: RegisterOptions) {
if (!isFileUrlOrNodeStyleSpecifier(parsed)) {
return defer()
}
const { pathname } = parsed
if (pathname === null || !posixPath.isAbsolute(pathname)) {
// If we are meant to handle this URL, then it has already been resolved to an absolute path by our resolver hook
return defer()
}

// Assigning to a new variable so it's clear that we have stopped thinking of it as a URL, and started using it like a native FS path
const fileName = pathname
const nativePath = fileURLToPath(url)

if (tsNodeInstance.ignored(fileName)) {
if (tsNodeInstance.ignored(nativePath)) {
return defer()
}

const emittedJs = tsNodeInstance.compile(sourceAsString, fileName)
const emittedJs = tsNodeInstance.compile(sourceAsString, nativePath)

return { source: emittedJs }
}
Expand Down
4 changes: 4 additions & 0 deletions src/externs.d.ts
@@ -0,0 +1,4 @@
declare module 'util.promisify' {
const _export: typeof import('util').promisify
export = _export
}

0 comments on commit 61b75c5

Please sign in to comment.