Skip to content

Commit fd43821

Browse files
authored
Remove create-require and yn dependencies (#1961)
* Remove create-require dependency * remove yn dep, too
1 parent 6b1fd40 commit fd43821

File tree

6 files changed

+18
-41
lines changed

6 files changed

+18
-41
lines changed

package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,11 +160,9 @@
160160
"acorn": "^8.4.1",
161161
"acorn-walk": "^8.1.1",
162162
"arg": "^4.1.0",
163-
"create-require": "^1.1.0",
164163
"diff": "^4.0.1",
165164
"make-error": "^1.1.1",
166-
"v8-compile-cache-lib": "^3.0.1",
167-
"yn": "3.1.1"
165+
"v8-compile-cache-lib": "^3.0.1"
168166
},
169167
"prettier": {
170168
"singleQuote": true

src/bin.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { join, resolve, dirname, parse as parsePath, relative } from 'path';
44
import { inspect } from 'util';
55
import Module = require('module');
66
let arg: typeof import('arg');
7-
import { parse, createRequire, hasOwnProperty, versionGteLt } from './util';
7+
import { parse, hasOwnProperty, versionGteLt } from './util';
88
import {
99
EVAL_FILENAME,
1010
EvalState,
@@ -739,7 +739,7 @@ function requireResolveNonCached(absoluteModuleSpecifier: string) {
739739
const { dir, base } = parsePath(absoluteModuleSpecifier);
740740
const relativeModuleSpecifier = `./${base}`;
741741

742-
const req = createRequire(
742+
const req = Module.createRequire(
743743
join(dir, 'imaginaryUncacheableRequireResolveScript')
744744
);
745745
return req.resolve(relativeModuleSpecifier, {

src/test/helpers/misc.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
/** types from ts-node under test */
22
import type * as tsNodeTypes from '../../index';
3-
import type _createRequire from 'create-require';
43
import { TEST_DIR } from './paths';
54
import { join } from 'path';
65
import { promisify } from 'util';
7-
const createRequire: typeof _createRequire = require('create-require');
6+
import { createRequire } from 'module';
87
export { tsNodeTypes };
98

10-
// `createRequire` does not exist on older node versions
119
export const testsDirRequire = createRequire(join(TEST_DIR, 'index.js'));
1210

1311
export const ts = testsDirRequire('typescript') as typeof import('typescript');

src/test/index.spec.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import {
1414
tsSupportsStableNodeNextNode16,
1515
} from './helpers';
1616
import { lstatSync } from 'fs';
17-
import type _createRequire from 'create-require';
1817
import { createExec } from './exec-helpers';
1918
import {
2019
BIN_CWD_PATH,

src/util.ts

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
1-
import {
2-
createRequire as nodeCreateRequire,
3-
createRequireFromPath as nodeCreateRequireFromPath,
4-
} from 'module';
5-
import type _createRequire from 'create-require';
6-
import * as ynModule from 'yn';
71
import { dirname } from 'path';
82

9-
/** @internal */
10-
export const createRequire =
11-
nodeCreateRequire ??
12-
nodeCreateRequireFromPath ??
13-
(require('create-require') as typeof _createRequire);
14-
153
/**
16-
* Wrapper around yn module that returns `undefined` instead of `null`.
17-
* This is implemented by yn v4, but we're staying on v3 to avoid v4's node 10 requirement.
184
* @internal
5+
* Copied from https://unpkg.com/[email protected]/index.js
6+
* Because people get weird when they see you have dependencies. /jk
7+
* This is a lazy way to make the dep number go down, we haven't touched this
8+
* dep in ages, and we didn't use all its features, so we stripped them.
199
*/
20-
export function yn(value: string | undefined) {
21-
return ynModule(value) ?? undefined;
10+
export function yn(input: string | undefined) {
11+
input = String(input).trim();
12+
13+
if (/^(?:y|yes|true|1)$/i.test(input)) {
14+
return true;
15+
}
16+
17+
if (/^(?:n|no|false|0)$/i.test(input)) {
18+
return false;
19+
}
2220
}
2321

2422
/**

yarn.lock

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1515,13 +1515,6 @@ __metadata:
15151515
languageName: node
15161516
linkType: hard
15171517

1518-
"create-require@npm:^1.1.0":
1519-
version: 1.1.1
1520-
resolution: "create-require@npm:1.1.1"
1521-
checksum: a9a1503d4390d8b59ad86f4607de7870b39cad43d929813599a23714831e81c520bddf61bcdd1f8e30f05fd3a2b71ae8538e946eb2786dc65c2bbc520f692eff
1522-
languageName: node
1523-
linkType: hard
1524-
15251518
"cross-spawn@npm:^7.0.0, cross-spawn@npm:^7.0.3":
15261519
version: 7.0.3
15271520
resolution: "cross-spawn@npm:7.0.3"
@@ -3832,7 +3825,6 @@ __metadata:
38323825
arg: ^4.1.0
38333826
ava: ^5.1.1
38343827
axios: ^0.21.1
3835-
create-require: ^1.1.0
38363828
diff: ^4.0.1
38373829
dprint: ^0.25.0
38383830
expect: 27.0.2
@@ -3849,7 +3841,6 @@ __metadata:
38493841
typescript: 4.7.4
38503842
typescript-json-schema: ^0.54.0
38513843
v8-compile-cache-lib: ^3.0.1
3852-
yn: 3.1.1
38533844
peerDependencies:
38543845
"@swc/core": ">=1.2.50"
38553846
"@swc/wasm": ">=1.2.50"
@@ -4218,13 +4209,6 @@ __metadata:
42184209
languageName: node
42194210
linkType: hard
42204211

4221-
"yn@npm:3.1.1":
4222-
version: 3.1.1
4223-
resolution: "yn@npm:3.1.1"
4224-
checksum: 2c487b0e149e746ef48cda9f8bad10fc83693cd69d7f9dcd8be4214e985de33a29c9e24f3c0d6bcf2288427040a8947406ab27f7af67ee9456e6b84854f02dd6
4225-
languageName: node
4226-
linkType: hard
4227-
42284212
"yocto-queue@npm:^1.0.0":
42294213
version: 1.0.0
42304214
resolution: "yocto-queue@npm:1.0.0"

0 commit comments

Comments
 (0)