Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: remove module aliases #4393

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .eslintrc.js
Expand Up @@ -75,7 +75,7 @@ module.exports = {
'error',
{
// 'fsevents' is ony available on macOS, and not installed on linux/windows
ignore: ['fsevents', 'help.md', 'is-reference', 'package.json', 'types']
ignore: ['fsevents', 'help.md']
}
],
'import/order': ['error', { alphabetize: { order: 'asc' } }],
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Expand Up @@ -13,4 +13,4 @@ test/hooks/tmp
test/tmp
test/typescript/typings
perf/
.nyc_output/
.nyc_output/
6 changes: 3 additions & 3 deletions cli/cli.ts
@@ -1,8 +1,8 @@
import process from 'process';
import help from 'help.md';
import { version } from 'package.json';
import argParser from 'yargs-parser';
import { version } from '../package.json';
import { commandAliases } from '../src/utils/options/mergeOptions';
import help from './help';
import run from './run/index';

const command = argParser(process.argv.slice(2), {
Expand All @@ -11,7 +11,7 @@ const command = argParser(process.argv.slice(2), {
});

if (command.help || (process.argv.length <= 2 && process.stdin.isTTY)) {
console.log(`\n${help.replace('__VERSION__', version)}\n`);
console.log(`\n${help}\n`);
} else if (command.version) {
console.log(`rollup v${version}`);
} else {
Expand Down
102 changes: 102 additions & 0 deletions cli/help.ts
@@ -0,0 +1,102 @@
import { version } from '../package.json';

export default `rollup version ${version}
=====================================

Usage: rollup [options] <entry file>

Basic options:

-c, --config <filename> Use this config file (if argument is used but value
is unspecified, defaults to rollup.config.js)
-d, --dir <dirname> Directory for chunks (if absent, prints to stdout)
-e, --external <ids> Comma-separate list of module IDs to exclude
-f, --format <format> Type of output (amd, cjs, es, iife, umd, system)
-g, --globals <pairs> Comma-separate list of \`moduleID:Global\` pairs
-h, --help Show this help message
-i, --input <filename> Input (alternative to <entry file>)
-m, --sourcemap Generate sourcemap (\`-m inline\` for inline map)
-n, --name <name> Name for UMD export
-o, --file <output> Single output file (if absent, prints to stdout)
-p, --plugin <plugin> Use the plugin specified (may be repeated)
-v, --version Show version number
-w, --watch Watch files in bundle and rebuild on changes
--amd.id <id> ID for AMD module (default is anonymous)
--amd.autoId Generate the AMD ID based off the chunk name
--amd.basePath <prefix> Path to prepend to auto generated AMD ID
--amd.define <name> Function to use in place of \`define\`
--assetFileNames <pattern> Name pattern for emitted assets
--banner <text> Code to insert at top of bundle (outside wrapper)
--chunkFileNames <pattern> Name pattern for emitted secondary chunks
--compact Minify wrapper code
--context <variable> Specify top-level \`this\` value
--entryFileNames <pattern> Name pattern for emitted entry chunks
--environment <values> Settings passed to config file (see example)
--no-esModule Do not add __esModule property
--exports <mode> Specify export mode (auto, default, named, none)
--extend Extend global variable defined by --name
--no-externalLiveBindings Do not generate code to support live bindings
--failAfterWarnings Exit with an error if the build produced warnings
--footer <text> Code to insert at end of bundle (outside wrapper)
--no-freeze Do not freeze namespace objects
--no-hoistTransitiveImports Do not hoist transitive imports into entry chunks
--no-indent Don't indent result
--no-interop Do not include interop block
--inlineDynamicImports Create single bundle when using dynamic imports
--intro <text> Code to insert at top of bundle (inside wrapper)
--minifyInternalExports Force or disable minification of internal exports
--namespaceToStringTag Create proper \`.toString\` methods for namespaces
--noConflict Generate a noConflict method for UMD globals
--outro <text> Code to insert at end of bundle (inside wrapper)
--preferConst Use \`const\` instead of \`var\` for exports
--no-preserveEntrySignatures Avoid facade chunks for entry points
--preserveModules Preserve module structure
--preserveModulesRoot Put preserved modules under this path at root level
--preserveSymlinks Do not follow symlinks when resolving files
--no-sanitizeFileName Do not replace invalid characters in file names
--shimMissingExports Create shim variables for missing exports
--silent Don't print warnings
--sourcemapExcludeSources Do not include source code in source maps
--sourcemapFile <file> Specify bundle position for source maps
--stdin=ext Specify file extension used for stdin input
--no-stdin Do not read "-" from stdin
--no-strict Don't emit \`"use strict";\` in the generated modules
--strictDeprecations Throw errors for deprecated features
--systemNullSetters Replace empty SystemJS setters with \`null\`
--no-treeshake Disable tree-shaking optimisations
--no-treeshake.annotations Ignore pure call annotations
--no-treeshake.moduleSideEffects Assume modules have no side-effects
--no-treeshake.propertyReadSideEffects Ignore property access side-effects
--no-treeshake.tryCatchDeoptimization Do not turn off try-catch-tree-shaking
--no-treeshake.unknownGlobalSideEffects Assume unknown globals do not throw
--waitForBundleInput Wait for bundle input files
--watch.buildDelay <number> Throttle watch rebuilds
--no-watch.clearScreen Do not clear the screen when rebuilding
--watch.skipWrite Do not write files to disk when watching
--watch.exclude <files> Exclude files from being watched
--watch.include <files> Limit watching to specified files
--validate Validate output

Examples:

# use settings in config file
rollup -c

# in config file, process.env.INCLUDE_DEPS === 'true'
# and process.env.BUILD === 'production'
rollup -c --environment INCLUDE_DEPS,BUILD:production

# create CommonJS bundle.js from src/main.js
rollup --format=cjs --file=bundle.js -- src/main.js

# create self-executing IIFE using \`window.jQuery\`
# and \`window._\` as external globals
rollup -f iife --globals jquery:jQuery,lodash:_ \
-i src/app.js -o build/app.js -m build/app.js.map

Notes:

* When piping to stdout, only inline sourcemaps are permitted

For more information visit https://rollupjs.org
`;
35 changes: 0 additions & 35 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Expand Up @@ -16,6 +16,7 @@
"ci:test": "npm run build:cjs && npm run build:bootstrap && npm run test:all",
"ci:test:only": "npm run build:cjs && npm run build:bootstrap && npm run test:only",
"ci:coverage": "npm run build:cjs && npm run build:bootstrap && nyc --reporter lcovonly mocha",
"generate:help": "node ./scripts/generate-help-module",
"lint": "eslint . --fix --cache && prettier --write \"**/*.md\"",
"lint:nofix": "eslint . && prettier --check \"**/*.md\"",
"lint:markdown": "prettier --write \"**/*.md\"",
Expand Down Expand Up @@ -58,7 +59,6 @@
"fsevents": "~2.3.2"
},
"devDependencies": {
"@rollup/plugin-alias": "^3.1.9",
"@rollup/plugin-buble": "^0.21.3",
"@rollup/plugin-commonjs": "^21.0.1",
"@rollup/plugin-json": "^4.1.0",
Expand Down Expand Up @@ -104,7 +104,6 @@
"requirejs": "^2.3.6",
"rollup": "^2.67.1",
"rollup-plugin-license": "^2.6.1",
"rollup-plugin-string": "^3.0.0",
"rollup-plugin-terser": "^7.0.2",
"rollup-plugin-thatworks": "^1.0.4",
"shx": "^0.3.4",
Expand Down
15 changes: 0 additions & 15 deletions rollup.config.ts
@@ -1,13 +1,10 @@
import { promises as fs } from 'fs';
import { resolve } from 'path';
import { env } from 'process';
import alias from '@rollup/plugin-alias';
import commonjs from '@rollup/plugin-commonjs';
import json from '@rollup/plugin-json';
import { nodeResolve } from '@rollup/plugin-node-resolve';
import typescript from '@rollup/plugin-typescript';
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';
import conditionalFsEventsImport from './build-plugins/conditional-fsevents-import';
Expand Down Expand Up @@ -50,27 +47,16 @@ const onwarn: WarningHandlerWithDefault = warning => {
throw new Error(warning.message);
};

const moduleAliases = {
entries: {
acorn: resolve('node_modules/acorn/dist/acorn.mjs'),
'help.md': resolve('cli/help.md'),
'package.json': resolve('package.json')
},
resolve: ['.js', '.json', '.md']
};

const treeshake = {
moduleSideEffects: false,
propertyReadSideEffects: false,
tryCatchDeoptimization: false
};

const nodePlugins = [
alias(moduleAliases),
nodeResolve(),
json(),
conditionalFsEventsImport(),
string({ include: '**/*.md' }),
commonjs({
ignoreTryCatch: false,
include: 'node_modules/**'
Expand Down Expand Up @@ -143,7 +129,6 @@ export default async function (
],
plugins: [
replaceBrowserModules(),
alias(moduleAliases),
nodeResolve({ browser: true }),
json(),
commonjs(),
Expand Down
18 changes: 18 additions & 0 deletions scripts/generate-help-module.js
@@ -0,0 +1,18 @@
'use strict';

const { promises: fs } = require('fs');
const { resolve } = require('path');

async function generateHelpModule() {
const mdFilename = resolve(__dirname, '../cli/help.md');
const mdContent = await fs.readFile(mdFilename, 'utf8');

const tsFilename = resolve(__dirname, '../cli/help.ts');
const tsContent = `import { version } from '../package.json';

export default \`${mdContent.replace('__VERSION__', '${version}').replace(/`/g, '\\`')}\`;
`;
await fs.writeFile(tsFilename, tsContent);
}

generateHelpModule();
2 changes: 1 addition & 1 deletion src/browser-entry.ts
@@ -1,2 +1,2 @@
export { default as rollup, defineConfig } from './rollup/rollup';
export { version as VERSION } from 'package.json';
export { version as VERSION } from '../package.json';
2 changes: 1 addition & 1 deletion src/node-entry.ts
@@ -1,3 +1,3 @@
export { default as rollup, defineConfig } from './rollup/rollup';
export { default as watch } from './watch/watch-proxy';
export { version as VERSION } from 'package.json';
export { version as VERSION } from '../package.json';
2 changes: 1 addition & 1 deletion src/rollup/rollup.ts
@@ -1,4 +1,4 @@
import { version as rollupVersion } from 'package.json';
import { version as rollupVersion } from '../../package.json';
import Bundle from '../Bundle';
import Graph from '../Graph';
import type { PluginDriver } from '../utils/PluginDriver';
Expand Down
2 changes: 1 addition & 1 deletion src/utils/PluginContext.ts
@@ -1,4 +1,4 @@
import { version as rollupVersion } from 'package.json';
import { version as rollupVersion } from '../../package.json';
import type Graph from '../Graph';
import type {
NormalizedInputOptions,
Expand Down
13 changes: 0 additions & 13 deletions typings/declarations.d.ts → typings/is-reference.d.ts
@@ -1,16 +1,3 @@
// internal
declare module 'help.md' {
const str: string;
export default str;
}

// external libs
declare module 'rollup-plugin-string' {
import type { PluginImpl } from 'rollup';

export const string: PluginImpl;
}

declare module 'is-reference' {
import type * as estree from 'estree';

Expand Down