Skip to content

Commit 4c6a7e0

Browse files
authored
Improve checkJs Typings (#666)
* Allow RegExp --externals only for the CLI argument * Fix globals generation for regex externals * Improved checkJs typings * spelling
1 parent 4b36427 commit 4c6a7e0

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

src/index.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -447,10 +447,12 @@ const shebang = {};
447447
function createConfig(options, entry, format, writeMeta) {
448448
let { pkg } = options;
449449

450+
/** @type {(string|RegExp)[]} */
450451
let external = ['dns', 'fs', 'path', 'url'].concat(
451452
options.entries.filter(e => e !== entry),
452453
);
453454

455+
/** @type {Record<string, string>} */
454456
let outputAliases = {};
455457
// since we transform src/index.js, we need to rename imports for it:
456458
if (options.multipleEntries) {
@@ -540,10 +542,15 @@ function createConfig(options, entry, format, writeMeta) {
540542

541543
if (nameCache === bareNameCache) nameCache = null;
542544

545+
/** @type {false | import('rollup').RollupCache} */
546+
let cache;
547+
if (modern) cache = false;
548+
543549
let config = {
550+
/** @type {import('rollup').InputOptions} */
544551
inputOptions: {
545552
// disable Rollup's cache for the modern build to prevent re-use of legacy transpiled modules:
546-
cache: modern ? false : undefined,
553+
cache,
547554

548555
input: entry,
549556
external: id => {
@@ -576,7 +583,8 @@ function createConfig(options, entry, format, writeMeta) {
576583
}),
577584
moduleAliases.length > 0 &&
578585
alias({
579-
resolve: EXTENSIONS,
586+
// @TODO: this is no longer supported, but didn't appear to be required?
587+
// resolve: EXTENSIONS,
580588
entries: moduleAliases,
581589
}),
582590
nodeResolve({
@@ -712,11 +720,11 @@ function createConfig(options, entry, format, writeMeta) {
712720
.filter(Boolean),
713721
},
714722

723+
/** @type {import('rollup').OutputOptions} */
715724
outputOptions: {
716725
paths: outputAliases,
717726
globals,
718727
strict: options.strict === true,
719-
legacy: true,
720728
freeze: false,
721729
esModule: false,
722730
sourcemap: options.sourcemap,

src/utils.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
1-
import fs from 'fs';
2-
import { promisify } from 'es6-promisify';
1+
import { promises as fs } from 'fs';
2+
3+
export const readFile = fs.readFile;
4+
5+
export const stat = fs.stat;
36

4-
export const readFile = promisify(fs.readFile);
5-
// export const writeFile = promisify(fs.writeFile);
6-
export const stat = promisify(fs.stat);
77
export const isDir = name =>
88
stat(name)
99
.then(stats => stats.isDirectory())
1010
.catch(() => false);
11+
1112
export const isFile = name =>
1213
stat(name)
1314
.then(stats => stats.isFile())
1415
.catch(() => false);
16+
1517
export const stdout = console.log.bind(console); // eslint-disable-line no-console
18+
1619
export const stderr = console.error.bind(console);
1720

1821
export const isTruthy = obj => {

0 commit comments

Comments
 (0)