diff --git a/.eslintrc.js b/.eslintrc.js index 30e12eaa53a..4a501ad0045 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -73,7 +73,10 @@ module.exports = { 'dot-notation': 'error', 'import/no-unresolved': [ 'error', - { ignore: ['package.json', 'is-reference', 'help.md', 'types'] } + { + // 'fsevents' is ony available on macOS, and not installed on linux/windows + ignore: ['fsevents', 'help.md', 'is-reference', 'package.json', 'types'] + } ], 'import/order': ['error', { alphabetize: { order: 'asc' } }], 'no-constant-condition': ['error', { checkLoops: false }], diff --git a/build-plugins/conditional-fsevents-import.ts b/build-plugins/conditional-fsevents-import.ts index 5378269cf20..ba3f22ce639 100644 --- a/build-plugins/conditional-fsevents-import.ts +++ b/build-plugins/conditional-fsevents-import.ts @@ -1,5 +1,5 @@ import MagicString from 'magic-string'; -import { Plugin } from 'rollup'; +import type { Plugin } from 'rollup'; const FSEVENTS_REQUIRE = "require('fsevents')"; const REPLACEMENT = "require('../../../src/watch/fsevents-importer').getFsEvents()"; diff --git a/package-lock.json b/package-lock.json index 5ef6a95cf8b..3651b4a138c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -20,20 +20,20 @@ "dev": true }, "@babel/core": { - "version": "7.16.7", - "resolved": "https://registry.npmjs.org/@babel/core/-/core-7.16.7.tgz", - "integrity": "sha512-aeLaqcqThRNZYmbMqtulsetOQZ/5gbR/dWruUCJcpas4Qoyy+QeagfDsPdMrqwsPRDNxJvBlRiZxxX7THO7qtA==", + "version": "7.16.10", + "resolved": "https://registry.npmjs.org/@babel/core/-/core-7.16.10.tgz", + "integrity": "sha512-pbiIdZbCiMx/MM6toR+OfXarYix3uz0oVsnNtfdAGTcCTu3w/JGF8JhirevXLBJUu0WguSZI12qpKnx7EeMyLA==", "dev": true, "requires": { "@babel/code-frame": "^7.16.7", - "@babel/generator": "^7.16.7", + "@babel/generator": "^7.16.8", "@babel/helper-compilation-targets": "^7.16.7", "@babel/helper-module-transforms": "^7.16.7", "@babel/helpers": "^7.16.7", - "@babel/parser": "^7.16.7", + "@babel/parser": "^7.16.10", "@babel/template": "^7.16.7", - "@babel/traverse": "^7.16.7", - "@babel/types": "^7.16.7", + "@babel/traverse": "^7.16.10", + "@babel/types": "^7.16.8", "convert-source-map": "^1.7.0", "debug": "^4.1.0", "gensync": "^1.0.0-beta.2", @@ -215,9 +215,9 @@ } }, "@babel/highlight": { - "version": "7.16.7", - "resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.16.7.tgz", - "integrity": "sha512-aKpPMfLvGO3Q97V0qhw/V2SWNWlwfJknuwAunU7wZLSfrM4xTBvg7E5opUVi1kJTBKihE38CPg4nBiqX83PWYw==", + "version": "7.16.10", + "resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.16.10.tgz", + "integrity": "sha512-5FnTQLSLswEj6IkgVw5KusNUUFY9ZGqe/TRFnP/BKYHYgfh7tc+C7mwiy95/yNP7Dh9x580Vv8r7u7ZfTBFxdw==", "dev": true, "requires": { "@babel/helper-validator-identifier": "^7.16.7", @@ -226,9 +226,9 @@ } }, "@babel/parser": { - "version": "7.16.8", - "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.16.8.tgz", - "integrity": "sha512-i7jDUfrVBWc+7OKcBzEe5n7fbv3i2fWtxKzzCvOjnzSxMfWMigAhtfJ7qzZNGFNMsCCd67+uz553dYKWXPvCKw==", + "version": "7.16.10", + "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.16.10.tgz", + "integrity": "sha512-Sm/S9Or6nN8uiFsQU1yodyDW3MWXQhFeqzMPM+t8MJjM+pLsnFVxFZzkpXKvUXh+Gz9cbMoYYs484+Jw/NTEFQ==", "dev": true }, "@babel/template": { @@ -243,9 +243,9 @@ } }, "@babel/traverse": { - "version": "7.16.8", - "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.16.8.tgz", - "integrity": "sha512-xe+H7JlvKsDQwXRsBhSnq1/+9c+LlQcCK3Tn/l5sbx02HYns/cn7ibp9+RV1sIUqu7hKg91NWsgHurO9dowITQ==", + "version": "7.16.10", + "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.16.10.tgz", + "integrity": "sha512-yzuaYXoRJBGMlBhsMJoUW7G1UmSb/eXr/JHYM/MsOJgavJibLwASijW7oXBdw3NQ6T0bW7Ty5P/VarOs9cHmqw==", "dev": true, "requires": { "@babel/code-frame": "^7.16.7", @@ -254,7 +254,7 @@ "@babel/helper-function-name": "^7.16.7", "@babel/helper-hoist-variables": "^7.16.7", "@babel/helper-split-export-declaration": "^7.16.7", - "@babel/parser": "^7.16.8", + "@babel/parser": "^7.16.10", "@babel/types": "^7.16.8", "debug": "^4.1.0", "globals": "^11.1.0" @@ -1134,9 +1134,9 @@ } }, "chokidar": { - "version": "3.5.2", - "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.5.2.tgz", - "integrity": "sha512-ekGhOnNVPgT77r4K/U3GDhu+FQ2S8TnK/s2KbIGXi0SZWuwkZ2QNyfWdZW+TVfn84DpEP7rLeCt2UI6bJ8GwbQ==", + "version": "3.5.3", + "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.5.3.tgz", + "integrity": "sha512-Dr3sfKRP6oTcjf2JmUmFJfeVMvXBdegxB0iVQ5eb2V10uFJUCAS8OByZdVAyVb8xXNz3GjjTgj9kLWsZTqE6kw==", "dev": true, "requires": { "anymatch": "~3.1.2", @@ -1370,9 +1370,9 @@ } }, "electron-to-chromium": { - "version": "1.4.47", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.47.tgz", - "integrity": "sha512-ZHc8i3/cgeCRK/vC7W2htAG6JqUmOUgDNn/f9yY9J8UjfLjwzwOVEt4MWmgJAdvmxyrsR5KIFA/6+kUHGY0eUA==", + "version": "1.4.49", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.49.tgz", + "integrity": "sha512-k/0t1TRfonHIp8TJKfjBu2cKj8MqYTiEpOhci+q7CVEE5xnCQnx1pTa+V8b/sdhe4S3PR4p4iceEQWhGrKQORQ==", "dev": true }, "emoji-regex": { @@ -3109,6 +3109,22 @@ "yargs-unparser": "2.0.0" }, "dependencies": { + "chokidar": { + "version": "3.5.2", + "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.5.2.tgz", + "integrity": "sha512-ekGhOnNVPgT77r4K/U3GDhu+FQ2S8TnK/s2KbIGXi0SZWuwkZ2QNyfWdZW+TVfn84DpEP7rLeCt2UI6bJ8GwbQ==", + "dev": true, + "requires": { + "anymatch": "~3.1.2", + "braces": "~3.0.2", + "fsevents": "~2.3.2", + "glob-parent": "~5.1.2", + "is-binary-path": "~2.1.0", + "is-glob": "~4.0.1", + "normalize-path": "~3.0.0", + "readdirp": "~3.6.0" + } + }, "debug": { "version": "4.3.2", "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.2.tgz", @@ -4562,9 +4578,9 @@ } }, "typescript": { - "version": "4.5.4", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.5.4.tgz", - "integrity": "sha512-VgYs2A2QIRuGphtzFV7aQJduJ2gyfTljngLzjpfW9FoYZF6xuw1W0vW9ghCKLfcWrCFxK81CSGRAvS1pn4fIUg==", + "version": "4.5.5", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.5.5.tgz", + "integrity": "sha512-TCTIul70LyWe6IJWT8QSYeA54WQe8EjQFU4wY52Fasj5UKx88LNYKCgBEHcOMOrFF1rKGbD8v/xcNWVUq9SymA==", "dev": true }, "unbox-primitive": { diff --git a/package.json b/package.json index 886e688487f..3337193c7fd 100644 --- a/package.json +++ b/package.json @@ -75,7 +75,7 @@ "acorn-jsx": "^5.3.2", "acorn-walk": "^8.2.0", "buble": "^0.20.0", - "chokidar": "^3.5.2", + "chokidar": "^3.5.3", "colorette": "^2.0.16", "core-js": "^3.20.3", "date-time": "^4.0.0", @@ -114,7 +114,7 @@ "systemjs": "^6.11.0", "terser": "^5.10.0", "tslib": "^2.3.1", - "typescript": "^4.5.4", + "typescript": "^4.5.5", "weak-napi": "^2.0.2", "yargs-parser": "^20.2.9" }, diff --git a/rollup.config.ts b/rollup.config.ts index 51ce7f40ace..6be0690ae8f 100644 --- a/rollup.config.ts +++ b/rollup.config.ts @@ -1,11 +1,12 @@ import { readFileSync } from 'fs'; -import path from 'path'; +import { resolve } from 'path'; +import process from 'process'; import alias from '@rollup/plugin-alias'; import commonjs from '@rollup/plugin-commonjs'; import json from '@rollup/plugin-json'; -import resolve from '@rollup/plugin-node-resolve'; +import { nodeResolve } from '@rollup/plugin-node-resolve'; import typescript from '@rollup/plugin-typescript'; -import { RollupOptions, WarningHandlerWithDefault } from 'rollup'; +import type { RollupOptions, WarningHandlerWithDefault } from 'rollup'; import { string } from 'rollup-plugin-string'; import { terser } from 'rollup-plugin-terser'; import addCliEntry from './build-plugins/add-cli-entry'; @@ -14,7 +15,7 @@ import emitModulePackageFile from './build-plugins/emit-module-package-file'; import esmDynamicImport from './build-plugins/esm-dynamic-import'; import getLicenseHandler from './build-plugins/generate-license-file'; import replaceBrowserModules from './build-plugins/replace-browser-modules'; -import pkg from './package.json'; +import { version } from './package.json'; const commitHash = (function () { try { @@ -24,15 +25,12 @@ const commitHash = (function () { } })(); -const now = new Date( - process.env.SOURCE_DATE_EPOCH - ? 1000 * parseInt(process.env.SOURCE_DATE_EPOCH) - : new Date().getTime() -).toUTCString(); +const { SOURCE_DATE_EPOCH } = process.env; +const now = new Date(SOURCE_DATE_EPOCH ? 1000 * +SOURCE_DATE_EPOCH : Date.now()).toUTCString(); const banner = `/* @license - Rollup.js v${pkg.version} + Rollup.js v${version} ${now} - commit ${commitHash} https://github.com/rollup/rollup @@ -50,11 +48,11 @@ const onwarn: WarningHandlerWithDefault = warning => { }; const moduleAliases = { - entries: [ - { find: 'help.md', replacement: path.resolve('cli/help.md') }, - { find: 'package.json', replacement: path.resolve('package.json') }, - { find: 'acorn', replacement: path.resolve('node_modules/acorn/dist/acorn.mjs') } - ], + entries: { + acorn: resolve('node_modules/acorn/dist/acorn.mjs'), + 'help.md': resolve('cli/help.md'), + 'package.json': resolve('package.json') + }, resolve: ['.js', '.json', '.md'] }; @@ -66,7 +64,7 @@ const treeshake = { const nodePlugins = [ alias(moduleAliases), - resolve(), + nodeResolve(), json(), conditionalFsEventsImport(), string({ include: '**/*.md' }), @@ -80,24 +78,8 @@ const nodePlugins = [ export default (command: Record): RollupOptions | RollupOptions[] => { const { collectLicenses, writeLicense } = getLicenseHandler(); const commonJSBuild: RollupOptions = { - // fsevents is a dependency of chokidar that cannot be bundled as it contains binary code - external: [ - 'buffer', - '@rollup/plugin-typescript', - 'assert', - 'crypto', - 'events', - 'fs', - 'fsevents', - 'module', - 'os', - 'path', - 'perf_hooks', - 'process', - 'stream', - 'url', - 'util' - ], + // 'fsevents' is a dependency of 'chokidar' that cannot be bundled as it contains binary code + external: ['fsevents'], input: { 'loadConfigFile.js': 'cli/run/loadConfigFile.ts', 'rollup.js': 'src/node-entry.ts' @@ -114,12 +96,7 @@ export default (command: Record): RollupOptions | RollupOptions format: 'cjs', freeze: false, generatedCode: 'es2015', - interop: id => { - if (id === 'fsevents') { - return 'defaultOnly'; - } - return 'default'; - }, + interop: 'default', manualChunks: { rollup: ['src/node-entry.ts'] }, sourcemap: true }, @@ -160,7 +137,7 @@ export default (command: Record): RollupOptions | RollupOptions plugins: [ replaceBrowserModules(), alias(moduleAliases), - resolve({ browser: true }), + nodeResolve({ browser: true }), json(), commonjs(), typescript(), diff --git a/src/watch/fsevents-importer.ts b/src/watch/fsevents-importer.ts index 34e76ac5a90..fde4c2815e7 100644 --- a/src/watch/fsevents-importer.ts +++ b/src/watch/fsevents-importer.ts @@ -1,18 +1,18 @@ -let fsEvents: unknown; +import type FsEvents from 'fsevents'; + +let fsEvents: typeof FsEvents; let fsEventsImportError: Error | undefined; export async function loadFsEvents(): Promise { - const moduleName = 'fsevents'; - try { - ({ default: fsEvents } = await import(moduleName)); + ({ default: fsEvents } = await import('fsevents')); } catch (err: any) { fsEventsImportError = err; } } // A call to this function will be injected into the chokidar code -export function getFsEvents(): unknown { +export function getFsEvents(): typeof FsEvents { if (fsEventsImportError) throw fsEventsImportError; return fsEvents; } diff --git a/typings/fsevents.d.ts b/typings/fsevents.d.ts new file mode 100644 index 00000000000..fe400f2c7cd --- /dev/null +++ b/typings/fsevents.d.ts @@ -0,0 +1,6 @@ +// 'fsevents' (which also has typings included) is an optional dependency installed on macOS, +// and not installed on linux/windows. this will provide (bogus) type information for +// linux/windows, and overwrite (replace) the types coming with the 'fsevents' module on macOS +declare module 'fsevents' { + export default {}; +}