Skip to content

Commit bf47068

Browse files
authored
exclude tests from npm package to shrink install size (#1273)
* exclude tests from npm package to shrink install size * fix test failures
1 parent 62641d9 commit bf47068

File tree

3 files changed

+29
-27
lines changed

3 files changed

+29
-27
lines changed

package.json

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,19 @@
3737
"ts-node-transpile-only": "dist/bin-transpile.js"
3838
},
3939
"files": [
40-
"transpilers/",
41-
"dist/",
42-
"dist-raw/",
43-
"register/",
44-
"esm/",
45-
"esm.mjs",
46-
"LICENSE",
47-
"tsconfig.schema.json",
48-
"tsconfig.schemastore-schema.json",
49-
"node10/",
50-
"node12/",
51-
"node14/"
40+
"/transpilers/",
41+
"/dist/",
42+
"!/dist/test",
43+
"/dist-raw/",
44+
"/register/",
45+
"/esm/",
46+
"/esm.mjs",
47+
"/LICENSE",
48+
"/tsconfig.schema.json",
49+
"/tsconfig.schemastore-schema.json",
50+
"/node10/",
51+
"/node12/",
52+
"/node14/"
5253
],
5354
"scripts": {
5455
"lint": "prettier --check .",
@@ -101,7 +102,7 @@
101102
"homepage": "https://github.com/TypeStrong/ts-node",
102103
"ava": {
103104
"files": [
104-
"dist/*.spec.js"
105+
"dist/test/*.spec.js"
105106
],
106107
"failWithoutAssertions": false,
107108
"timeout": "300s"

src/index.spec.ts renamed to src/test/index.spec.ts

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { tmpdir } from 'os';
1111
import semver = require('semver');
1212
import ts = require('typescript');
1313
import proxyquire = require('proxyquire');
14-
import type * as tsNodeTypes from './index';
14+
import type * as tsNodeTypes from '../index';
1515
import * as fs from 'fs';
1616
import {
1717
unlinkSync,
@@ -64,8 +64,9 @@ function exec(
6464
);
6565
}
6666

67-
const ROOT_DIR = resolve(__dirname, '..');
68-
const TEST_DIR = join(__dirname, '../tests');
67+
const ROOT_DIR = resolve(__dirname, '../..');
68+
const DIST_DIR = resolve(__dirname, '..');
69+
const TEST_DIR = join(__dirname, '../../tests');
6970
const PROJECT = join(TEST_DIR, 'tsconfig.json');
7071
const BIN_PATH = join(TEST_DIR, 'node_modules/.bin/ts-node');
7172
const BIN_SCRIPT_PATH = join(TEST_DIR, 'node_modules/.bin/ts-node-script');
@@ -93,7 +94,7 @@ test.suite('ts-node', (test) => {
9394
const cmdNoProject = `"${BIN_PATH}"`;
9495

9596
test('should export the correct version', () => {
96-
expect(VERSION).to.equal(require('../package.json').version);
97+
expect(VERSION).to.equal(require('../../package.json').version);
9798
});
9899
test('should export all CJS entrypoints', () => {
99100
// Ensure our package.json "exports" declaration allows `require()`ing all our entrypoints
@@ -900,7 +901,7 @@ test.suite('ts-node', (test) => {
900901
jsx: 'preserve',
901902
},
902903
}),
903-
moduleTestPath: require.resolve('../tests/module'),
904+
moduleTestPath: require.resolve('../../tests/module'),
904905
};
905906
})
906907
);
@@ -973,8 +974,8 @@ test.suite('ts-node', (test) => {
973974
});
974975

975976
try {
976-
expect(require('../tests/scope/a').ext).to.equal('.ts');
977-
expect(require('../tests/scope/b').ext).to.equal('.ts');
977+
expect(require('../../tests/scope/a').ext).to.equal('.ts');
978+
expect(require('../../tests/scope/b').ext).to.equal('.ts');
978979
} finally {
979980
compilers.forEach((c) => c.enabled(false));
980981
}
@@ -991,28 +992,28 @@ test.suite('ts-node', (test) => {
991992
}
992993

993994
test('should compile through js and ts', () => {
994-
const m = require('../tests/complex');
995+
const m = require('../../tests/complex');
995996

996997
expect(m.example()).to.equal('example');
997998
});
998999

9991000
test('should work with proxyquire', () => {
1000-
const m = proxyquire('../tests/complex', {
1001+
const m = proxyquire('../../tests/complex', {
10011002
'./example': 'hello',
10021003
});
10031004

10041005
expect(m.example()).to.equal('hello');
10051006
});
10061007

10071008
test('should work with `require.cache`', () => {
1008-
const { example1, example2 } = require('../tests/require-cache');
1009+
const { example1, example2 } = require('../../tests/require-cache');
10091010

10101011
expect(example1).to.not.equal(example2);
10111012
});
10121013

10131014
test('should use source maps', async () => {
10141015
try {
1015-
require('../tests/throw');
1016+
require('../../tests/throw');
10161017
} catch (error) {
10171018
expect(error.stack).to.contain(
10181019
[
@@ -1047,7 +1048,7 @@ test.suite('ts-node', (test) => {
10471048
require.extensions['.tsx'] = old;
10481049
});
10491050
try {
1050-
require('../tests/with-jsx.tsx');
1051+
require('../../tests/with-jsx.tsx');
10511052
} catch (error) {
10521053
expect(error.stack).to.contain('SyntaxError: Unexpected token');
10531054
}
@@ -1103,13 +1104,13 @@ test.suite('ts-node', (test) => {
11031104
disallowed: string[]
11041105
) {
11051106
for (const ext of allowed) {
1106-
expect(ignored(join(__dirname, `index${ext}`))).equal(
1107+
expect(ignored(join(DIST_DIR, `index${ext}`))).equal(
11071108
false,
11081109
`should accept ${ext} files`
11091110
);
11101111
}
11111112
for (const ext of disallowed) {
1112-
expect(ignored(join(__dirname, `index${ext}`))).equal(
1113+
expect(ignored(join(DIST_DIR, `index${ext}`))).equal(
11131114
true,
11141115
`should ignore ${ext} files`
11151116
);
File renamed without changes.

0 commit comments

Comments
 (0)