Skip to content

Commit 2256dcd

Browse files
chore: remove external from config (#4355)
* chore: remove external from config * simplify named imports * nits * fix: mark fsevents as external * fix: set interop to default * Revert "fix: mark fsevents as external" This reverts commit 4a5fa73. * chore: bump chokidar * simplify alias plugin params * Revert "Revert "fix: mark fsevents as external"" This reverts commit 2ef6c5b. * add bogus types for fsevents * exclude fsevents from import linting * add back comment * bump typescript * re-use env var Co-authored-by: Lukas Taegert-Atkinson <[email protected]>
1 parent d1079a3 commit 2256dcd

7 files changed

Lines changed: 78 additions & 76 deletions

File tree

.eslintrc.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,10 @@ module.exports = {
7373
'dot-notation': 'error',
7474
'import/no-unresolved': [
7575
'error',
76-
{ ignore: ['package.json', 'is-reference', 'help.md', 'types'] }
76+
{
77+
// 'fsevents' is ony available on macOS, and not installed on linux/windows
78+
ignore: ['fsevents', 'help.md', 'is-reference', 'package.json', 'types']
79+
}
7780
],
7881
'import/order': ['error', { alphabetize: { order: 'asc' } }],
7982
'no-constant-condition': ['error', { checkLoops: false }],

build-plugins/conditional-fsevents-import.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import MagicString from 'magic-string';
2-
import { Plugin } from 'rollup';
2+
import type { Plugin } from 'rollup';
33

44
const FSEVENTS_REQUIRE = "require('fsevents')";
55
const REPLACEMENT = "require('../../../src/watch/fsevents-importer').getFsEvents()";

package-lock.json

Lines changed: 42 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
"acorn-jsx": "^5.3.2",
7676
"acorn-walk": "^8.2.0",
7777
"buble": "^0.20.0",
78-
"chokidar": "^3.5.2",
78+
"chokidar": "^3.5.3",
7979
"colorette": "^2.0.16",
8080
"core-js": "^3.20.3",
8181
"date-time": "^4.0.0",
@@ -114,7 +114,7 @@
114114
"systemjs": "^6.11.0",
115115
"terser": "^5.10.0",
116116
"tslib": "^2.3.1",
117-
"typescript": "^4.5.4",
117+
"typescript": "^4.5.5",
118118
"weak-napi": "^2.0.2",
119119
"yargs-parser": "^20.2.9"
120120
},

rollup.config.ts

Lines changed: 18 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import { readFileSync } from 'fs';
2-
import path from 'path';
2+
import { resolve } from 'path';
3+
import process from 'process';
34
import alias from '@rollup/plugin-alias';
45
import commonjs from '@rollup/plugin-commonjs';
56
import json from '@rollup/plugin-json';
6-
import resolve from '@rollup/plugin-node-resolve';
7+
import { nodeResolve } from '@rollup/plugin-node-resolve';
78
import typescript from '@rollup/plugin-typescript';
8-
import { RollupOptions, WarningHandlerWithDefault } from 'rollup';
9+
import type { RollupOptions, WarningHandlerWithDefault } from 'rollup';
910
import { string } from 'rollup-plugin-string';
1011
import { terser } from 'rollup-plugin-terser';
1112
import addCliEntry from './build-plugins/add-cli-entry';
@@ -14,7 +15,7 @@ import emitModulePackageFile from './build-plugins/emit-module-package-file';
1415
import esmDynamicImport from './build-plugins/esm-dynamic-import';
1516
import getLicenseHandler from './build-plugins/generate-license-file';
1617
import replaceBrowserModules from './build-plugins/replace-browser-modules';
17-
import pkg from './package.json';
18+
import { version } from './package.json';
1819

1920
const commitHash = (function () {
2021
try {
@@ -24,15 +25,12 @@ const commitHash = (function () {
2425
}
2526
})();
2627

27-
const now = new Date(
28-
process.env.SOURCE_DATE_EPOCH
29-
? 1000 * parseInt(process.env.SOURCE_DATE_EPOCH)
30-
: new Date().getTime()
31-
).toUTCString();
28+
const { SOURCE_DATE_EPOCH } = process.env;
29+
const now = new Date(SOURCE_DATE_EPOCH ? 1000 * +SOURCE_DATE_EPOCH : Date.now()).toUTCString();
3230

3331
const banner = `/*
3432
@license
35-
Rollup.js v${pkg.version}
33+
Rollup.js v${version}
3634
${now} - commit ${commitHash}
3735
3836
https://github.com/rollup/rollup
@@ -50,11 +48,11 @@ const onwarn: WarningHandlerWithDefault = warning => {
5048
};
5149

5250
const moduleAliases = {
53-
entries: [
54-
{ find: 'help.md', replacement: path.resolve('cli/help.md') },
55-
{ find: 'package.json', replacement: path.resolve('package.json') },
56-
{ find: 'acorn', replacement: path.resolve('node_modules/acorn/dist/acorn.mjs') }
57-
],
51+
entries: {
52+
acorn: resolve('node_modules/acorn/dist/acorn.mjs'),
53+
'help.md': resolve('cli/help.md'),
54+
'package.json': resolve('package.json')
55+
},
5856
resolve: ['.js', '.json', '.md']
5957
};
6058

@@ -66,7 +64,7 @@ const treeshake = {
6664

6765
const nodePlugins = [
6866
alias(moduleAliases),
69-
resolve(),
67+
nodeResolve(),
7068
json(),
7169
conditionalFsEventsImport(),
7270
string({ include: '**/*.md' }),
@@ -80,24 +78,8 @@ const nodePlugins = [
8078
export default (command: Record<string, unknown>): RollupOptions | RollupOptions[] => {
8179
const { collectLicenses, writeLicense } = getLicenseHandler();
8280
const commonJSBuild: RollupOptions = {
83-
// fsevents is a dependency of chokidar that cannot be bundled as it contains binary code
84-
external: [
85-
'buffer',
86-
'@rollup/plugin-typescript',
87-
'assert',
88-
'crypto',
89-
'events',
90-
'fs',
91-
'fsevents',
92-
'module',
93-
'os',
94-
'path',
95-
'perf_hooks',
96-
'process',
97-
'stream',
98-
'url',
99-
'util'
100-
],
81+
// 'fsevents' is a dependency of 'chokidar' that cannot be bundled as it contains binary code
82+
external: ['fsevents'],
10183
input: {
10284
'loadConfigFile.js': 'cli/run/loadConfigFile.ts',
10385
'rollup.js': 'src/node-entry.ts'
@@ -114,12 +96,7 @@ export default (command: Record<string, unknown>): RollupOptions | RollupOptions
11496
format: 'cjs',
11597
freeze: false,
11698
generatedCode: 'es2015',
117-
interop: id => {
118-
if (id === 'fsevents') {
119-
return 'defaultOnly';
120-
}
121-
return 'default';
122-
},
99+
interop: 'default',
123100
manualChunks: { rollup: ['src/node-entry.ts'] },
124101
sourcemap: true
125102
},
@@ -160,7 +137,7 @@ export default (command: Record<string, unknown>): RollupOptions | RollupOptions
160137
plugins: [
161138
replaceBrowserModules(),
162139
alias(moduleAliases),
163-
resolve({ browser: true }),
140+
nodeResolve({ browser: true }),
164141
json(),
165142
commonjs(),
166143
typescript(),

src/watch/fsevents-importer.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
let fsEvents: unknown;
1+
import type FsEvents from 'fsevents';
2+
3+
let fsEvents: typeof FsEvents;
24
let fsEventsImportError: Error | undefined;
35

46
export async function loadFsEvents(): Promise<void> {
5-
const moduleName = 'fsevents';
6-
77
try {
8-
({ default: fsEvents } = await import(moduleName));
8+
({ default: fsEvents } = await import('fsevents'));
99
} catch (err: any) {
1010
fsEventsImportError = err;
1111
}
1212
}
1313

1414
// A call to this function will be injected into the chokidar code
15-
export function getFsEvents(): unknown {
15+
export function getFsEvents(): typeof FsEvents {
1616
if (fsEventsImportError) throw fsEventsImportError;
1717
return fsEvents;
1818
}

typings/fsevents.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// 'fsevents' (which also has typings included) is an optional dependency installed on macOS,
2+
// and not installed on linux/windows. this will provide (bogus) type information for
3+
// linux/windows, and overwrite (replace) the types coming with the 'fsevents' module on macOS
4+
declare module 'fsevents' {
5+
export default {};
6+
}

0 commit comments

Comments
 (0)