Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: rollup/plugins
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 5452bf266ac76e5c519f1b240679d11674e30284
Choose a base ref
...
head repository: rollup/plugins
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 007acf15c7605e4ebe77afc7f4e6f3c0c8e6a1b1
Choose a head ref
  • 18 commits
  • 60 files changed
  • 9 contributors

Commits on Jan 23, 2023

  1. chore(release): terser v0.4.0

    Release Workflow committed Jan 23, 2023
    1
    Copy the full SHA
    bc5cf91 View commit details

Commits on Apr 4, 2023

  1. 1
    Copy the full SHA
    9ca975e View commit details
  2. chore(release): alias v4.0.4

    Release Workflow committed Apr 4, 2023
    1
    Copy the full SHA
    41686bc View commit details
  3. feat(swc): initial release (#1412)

    * feat(swc): plugin for the speedy web compiler
    
    * fix(swc): types definition
    
    * fix(swc): use type infering for renderChunk
    
    * types(swc): remove unnecessary type import
    
    * types(swc): remove unnecessary type import
    
    * style(swc): fix linting issues
    
    * style(swc): capitalize babel string
    
    * docs(swc): mention alternatives in README.md
    
    * fix(swc): use transform instead renderChunk hook
    
    * fix(swc): move swc options to object property
    
    * test(swc): add typescript test for verifying transformation
    
    * style(swc): remove logging
    
    * style(swc): fix styling and spacing in README.md
    
    * build: define swc as dep instead peer-dep
    
    * fix: set engine version to >= v14.0
    
    * fix: set swc as peer-dep + specified rollup v3 as min version
    
    * docs: updated min node engine version in README
    tada5hi authored Apr 4, 2023
    2
    Copy the full SHA
    f8b251c View commit details
  4. chore(release): swc v0.1.0

    Release Workflow committed Apr 4, 2023
    2
    Copy the full SHA
    93a95d8 View commit details
  5. feat(esm-shim): initial release (#1415)

    * feat(commonjs-shim): initial release
    
    * build(commonjs-shim): fix pnpm lock file
    
    * build(commonjs-shim): fix type generation
    
    * build(commonjs-shim): use default procedure to provide types
    
    * fix: refactor & implemented requested changes
    
    * build: fix frozen lock file
    
    * docs: add unbuild reference + use tsconfig file link
    
    * fix: renderChunk arg + add match-all polyfill
    tada5hi authored Apr 4, 2023
    2
    Copy the full SHA
    3b20853 View commit details
  6. chore(release): esm-shim v0.1.0

    Release Workflow committed Apr 4, 2023
    1
    Copy the full SHA
    b4abf23 View commit details
  7. 1
    Copy the full SHA
    38e5ff0 View commit details
  8. feat(alias)!: resolve entry id (#1402)

    BREAKING CHANGE: Aliased path without an importer (e.g. Rollup input) will also be resolved
    bluwy authored Apr 4, 2023
    1
    Copy the full SHA
    a0242b2 View commit details
  9. chore(release): alias v5.0.0

    Release Workflow committed Apr 4, 2023
    1
    Copy the full SHA
    abda5cf View commit details
  10. docs(auto-install): add pnpm to package manager option (#1436)

    * fix readme
    
    * docs: refine change
    
    ---------
    
    Co-authored-by: Andrew Powell <shellscape@users.noreply.github.com>
    cunzaizhuyi and shellscape authored Apr 4, 2023
    1
    Copy the full SHA
    7eb2fbc View commit details
  11. chore(release): auto-install v3.0.4

    Release Workflow committed Apr 4, 2023
    1
    Copy the full SHA
    65aa1cd View commit details
  12. fix(node-resolve): bump is-builtin-module version, imports with a tra…

    …iling slash (#1424)
    
    * Bump the version of is-builtin-module to include the fix for imports with a trailing slash
    
    * Add tests for bypassing builtin modules with a trailing slash
    
    ---------
    
    Co-authored-by: Andrew Powell <shellscape@users.noreply.github.com>
    Robert Sweeney and shellscape authored Apr 4, 2023
    1
    Copy the full SHA
    aa5a994 View commit details
  13. chore(release): node-resolve v15.0.2

    Release Workflow committed Apr 4, 2023
    1
    Copy the full SHA
    9919bf2 View commit details
  14. feat(typescript): write declaration files in configured directory for…

    … `output.file` (#1378)
    
    * fix(typescript): Add missing types for `resolve`
    
    Signed-off-by: Ferdinand Thiessen <rpm@fthiessen.de>
    
    * feat(utils): Add test function `getFiles`
    
    This function returns the file names and content as
    rollup would write to filesystem.
    Emulating `handleGenerateWrite` and `writeOutputFile`.
    
    Signed-off-by: Ferdinand Thiessen <rpm@fthiessen.de>
    
    * fix(typescript): Fix writing declarations when `output.file` is used
    
    This fixes writing declarations into the configured `declarationDir`
    when configured rollup build with `output.file` instead of `output.dir`.
    
    Signed-off-by: Ferdinand Thiessen <rpm@fthiessen.de>
    
    * docs(typescript): Remove now unneeded documentation of non functional workaround
    
    Signed-off-by: Ferdinand Thiessen <rpm@fthiessen.de>
    
    * fix: Make `generateBundle` function more self explaining
    
    Signed-off-by: Ferdinand Thiessen <rpm@fthiessen.de>
    
    ---------
    
    Signed-off-by: Ferdinand Thiessen <rpm@fthiessen.de>
    susnux authored Apr 4, 2023
    1
    Copy the full SHA
    96b0338 View commit details
  15. chore(release): typescript v11.1.0

    Release Workflow committed Apr 4, 2023
    1
    Copy the full SHA
    e1bb4bd View commit details

Commits on Apr 9, 2023

  1. 1
    Copy the full SHA
    6f0a441 View commit details
  2. chore(release): terser v0.4.1

    Release Workflow committed Apr 9, 2023
    Copy the full SHA
    007acf1 View commit details
Showing with 1,072 additions and 94 deletions.
  1. +2 −0 CODEOWNERS
  2. +2 −0 README.md
  3. +16 −0 packages/alias/CHANGELOG.md
  4. +1 −1 packages/alias/README.md
  5. +1 −1 packages/alias/package.json
  6. +0 −3 packages/alias/src/index.ts
  7. +2 −2 packages/alias/test/test.mjs
  8. +8 −0 packages/auto-install/CHANGELOG.md
  9. +7 −3 packages/auto-install/README.md
  10. +1 −1 packages/auto-install/package.json
  11. +9 −0 packages/esm-shim/CHANGELOG.md
  12. +57 −0 packages/esm-shim/README.md
  13. +70 −0 packages/esm-shim/package.json
  14. +10 −0 packages/esm-shim/rollup.config.mjs
  15. +14 −0 packages/esm-shim/src/constants.ts
  16. +10 −0 packages/esm-shim/src/index.ts
  17. +16 −0 packages/esm-shim/src/module.ts
  18. +6 −0 packages/esm-shim/src/types.ts
  19. +50 −0 packages/esm-shim/src/utils.ts
  20. +1 −0 packages/esm-shim/test/fixtures/child.js
  21. +3 −0 packages/esm-shim/test/fixtures/cjs.js
  22. +51 −0 packages/esm-shim/test/snapshots/test.js.md
  23. BIN packages/esm-shim/test/snapshots/test.js.snap
  24. +43 −0 packages/esm-shim/test/test.js
  25. +14 −0 packages/esm-shim/test/types.ts
  26. +4 −0 packages/esm-shim/tsconfig.json
  27. +8 −0 packages/esm-shim/types/index.d.ts
  28. +21 −0 packages/esm-shim/unbuild.license
  29. +8 −0 packages/node-resolve/CHANGELOG.md
  30. +2 −2 packages/node-resolve/package.json
  31. +2 −2 packages/node-resolve/src/resolveImportSpecifiers.js
  32. +3 −0 packages/node-resolve/test/fixtures/prefer-local.js
  33. +18 −0 packages/node-resolve/test/prefer-builtins.js
  34. +9 −0 packages/swc/CHANGELOG.md
  35. +70 −0 packages/swc/README.md
  36. +73 −0 packages/swc/package.json
  37. +10 −0 packages/swc/rollup.config.mjs
  38. +5 −0 packages/swc/src/index.ts
  39. +36 −0 packages/swc/src/module.ts
  40. +5 −0 packages/swc/src/type.ts
  41. +1 −0 packages/swc/test/fixtures/export-default.js
  42. +1 −0 packages/swc/test/fixtures/export.js
  43. +3 −0 packages/swc/test/fixtures/test.ts
  44. +7 −0 packages/swc/test/fixtures/unminified.js
  45. +85 −0 packages/swc/test/test.js
  46. +14 −0 packages/swc/test/types.ts
  47. +8 −0 packages/swc/tsconfig.json
  48. +11 −0 packages/swc/types/index.d.ts
  49. +16 −0 packages/terser/CHANGELOG.md
  50. +1 −1 packages/terser/package.json
  51. +6 −1 packages/terser/types/index.d.ts
  52. +8 −0 packages/typescript/CHANGELOG.md
  53. +0 −48 packages/typescript/README.md
  54. +2 −1 packages/typescript/package.json
  55. +22 −16 packages/typescript/src/index.ts
  56. +1 −1 packages/typescript/test/fixtures/incremental-single/tsconfig.tsbuildinfo
  57. +33 −6 packages/typescript/test/test.js
  58. +146 −4 pnpm-lock.yaml
  59. +10 −0 util/test.d.ts
  60. +29 −1 util/test.js
2 changes: 2 additions & 0 deletions CODEOWNERS
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
* @shellscape

/packages/babel/ @Andarist
/packages/esm-shim/ @tada5hi
/packages/image/ @tjenkinson
/packages/node-resolve/ @tjenkinson
/packages/swc/ @tada5hi
/packages/terser/ @tada5hi
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -30,6 +30,7 @@ This repository houses plugins that Rollup considers critical to every day use o
| [dsv](packages/dsv) | Convert .csv and .tsv files into JavaScript modules with d3-dsv |
| [dynamic-import-vars](packages/dynamic-import-vars) | Resolving dynamic imports that contain variables. |
| [eslint](packages/eslint) | Verify entry point and all imported files with ESLint |
| [esm-shim](packages/esm-shim) | Replace cjs syntax for esm output bundles |
| [graphql](packages/graphql) | Convert .gql/.graphql files to ES6 modules |
| [html](packages/html) | Create HTML files to serve Rollup bundles |
| [image](packages/image) | Import JPG, PNG, GIF, SVG, and WebP files |
@@ -42,6 +43,7 @@ This repository houses plugins that Rollup considers critical to every day use o
| [run](packages/run) | Run your bundles in Node once they're built |
| [strip](packages/strip) | Remove debugger statements and functions like assert.equal and console.log from your code |
| [sucrase](packages/sucrase) | Compile TypeScript, Flow, JSX, etc with Sucrase |
| [swc](packages/swc) | Transpile TypeScript/JavaScript with the speedy-web-compiler |
| [terser](packages/terser) | Generate a minified output bundle with terser |
| [typescript](packages/typescript) | Integration between Rollup and Typescript |
| [url](packages/url) | Import files as data-URIs or ES Modules |
16 changes: 16 additions & 0 deletions packages/alias/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
# @rollup/plugin-alias ChangeLog

## v5.0.0

_2023-04-04_

### Breaking Changes

- feat: resolve entry id [#1402](https://github.com/rollup/plugins/pull/1402)

## v4.0.4

_2023-04-04_

### Updates

- docs: fix README esm error [#1451](https://github.com/rollup/plugins/pull/1451)

## v4.0.3

_2023-01-20_
2 changes: 1 addition & 1 deletion packages/alias/README.md
Original file line number Diff line number Diff line change
@@ -50,7 +50,7 @@ Create a `rollup.config.js` [configuration file](https://www.rollupjs.org/guide/
```js
import alias from '@rollup/plugin-alias';

module.exports = {
export default {
input: 'src/index.js',
output: {
dir: 'output',
2 changes: 1 addition & 1 deletion packages/alias/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rollup/plugin-alias",
"version": "4.0.3",
"version": "5.0.0",
"publishConfig": {
"access": "public"
},
3 changes: 0 additions & 3 deletions packages/alias/src/index.ts
Original file line number Diff line number Diff line change
@@ -81,9 +81,6 @@ export default function alias(options: RollupAliasOptions = {}): Plugin {
);
},
resolveId(importee, importer, resolveOptions) {
if (!importer) {
return null;
}
// First match is supposed to be the correct one
const matchedEntry = entries.find((entry) => matches(entry.find, importee));
if (!matchedEntry) {
4 changes: 2 additions & 2 deletions packages/alias/test/test.mjs
Original file line number Diff line number Diff line change
@@ -163,14 +163,14 @@ test('Will not confuse modules with similar names', (t) =>
]
).then((result) => t.deepEqual(result, [null, null, null])));

test('Leaves entry file untouched if matches alias', (t) =>
test('Alias entry file', (t) =>
resolveAliasWithRollup(
{
entries: [{ find: 'abacaxi', replacement: './abacaxi' }]
},
// eslint-disable-next-line no-undefined
[{ source: 'abacaxi/entry.js' }]
).then((result) => t.deepEqual(result, [null])));
).then((result) => t.deepEqual(result, ['./abacaxi/entry.js'])));

test('i/am/a/file', (t) =>
resolveAliasWithRollup(
8 changes: 8 additions & 0 deletions packages/auto-install/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# @rollup/plugin-auto-install ChangeLog

## v3.0.4

_2023-04-04_

### Updates

- docs: add pnpm to package manager option [#1436](https://github.com/rollup/plugins/pull/1436)

## v3.0.3

_2023-01-20_
10 changes: 7 additions & 3 deletions packages/auto-install/README.md
Original file line number Diff line number Diff line change
@@ -56,10 +56,14 @@ Specifies the location on disk of the target `package.json` file. If the file do

### `manager`

Type: `String`<br>
Default: `see below`
Type: `'pnpm'|'yarn'|'npm'`<br>
Default: determined at runtime

Specifies the package manager to use. If not specified:

Specifies the package manager to use; `npm` or `yarn`. If not specified, the plugin will default to `yarn` if `yarn.lock` exists, or `npm` otherwise.
- `'pnpm'` if `pnpm-lock.yaml` exists
- `'yarn'` if `yarn.lock` exists
- `'npm'` otherwise

## Credits

2 changes: 1 addition & 1 deletion packages/auto-install/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rollup/plugin-auto-install",
"version": "3.0.3",
"version": "3.0.4",
"publishConfig": {
"access": "public"
},
9 changes: 9 additions & 0 deletions packages/esm-shim/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# @rollup/plugin-esm-shim ChangeLog

## v0.1.0

_2023-04-04_

### Features

- feat: initial release [#1415](https://github.com/rollup/plugins/pull/1415)
57 changes: 57 additions & 0 deletions packages/esm-shim/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
[npm]: https://img.shields.io/npm/v/@rollup/plugin-esm-shim
[npm-url]: https://www.npmjs.com/package/@rollup/plugin-esm-shim
[size]: https://packagephobia.now.sh/badge?p=@rollup/plugin-esm-shim
[size-url]: https://packagephobia.now.sh/result?p=@rollup/plugin-esm-shim

[![npm][npm]][npm-url]
[![size][size]][size-url]
[![libera manifesto](https://img.shields.io/badge/libera-manifesto-lightgrey.svg)](https://liberamanifesto.com)

# @rollup/plugin-esm-shim

🍣 A Rollup plugin to replace CJS global variables within esm output bundles.

The list of global variables that are shimmed are:

- `__filename`: This variable corresponds to the file path of the generated bundle file.
- `__dirname`: This variable corresponds to the folder path of the created bundle file.
- `require`: Corresponds to a function to import modules in a synchronous way.

## Requirements

This plugin requires an [LTS](https://github.com/nodejs/Release) Node version (v14.0.0+) and Rollup v2.0+.

## Install

Using npm:

```console
npm install @rollup/plugin-esm-shim --save-dev
```

## Usage

Create a `rollup.config.js` [configuration file](https://www.rollupjs.org/guide/en/#configuration-files) and import the plugin:

```typescript
import esmShim from '@rollup/plugin-esm-shim';

export default {
input: 'src/index.js',
output: {
dir: 'output',
format: 'cjs'
},
plugins: [esmShim()]
};
```

Then call `rollup` either via the [CLI](https://www.rollupjs.org/guide/en/#command-line-reference) or the [API](https://www.rollupjs.org/guide/en/#javascript-api).

## Meta

[CONTRIBUTING](/.github/CONTRIBUTING.md)

[LICENSE (MIT)](/LICENSE)

Portions of this code were used with permission from [unbuild](https://github.com/unjs/unbuild). [unbuild LICENSE](./unbuild.LICENSE)
70 changes: 70 additions & 0 deletions packages/esm-shim/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{
"name": "@rollup/plugin-esm-shim",
"version": "0.1.0",
"publishConfig": {
"access": "public"
},
"description": "Generate minified bundle",
"license": "MIT",
"repository": {
"url": "rollup/plugins",
"directory": "packages/esm-shim"
},
"author": "Peter Placzek <peter.placzek1996@gmail.com>",
"homepage": "https://github.com/rollup/plugins/tree/master/packages/esm-shim#readme",
"bugs": "https://github.com/rollup/plugins/issues",
"main": "dist/cjs/index.js",
"module": "dist/es/index.js",
"exports": {
"types": "./types/index.d.ts",
"import": "./dist/es/index.js",
"default": "./dist/cjs/index.js"
},
"engines": {
"node": ">=14.0.0"
},
"scripts": {
"build": "rollup -c",
"ci:coverage": "nyc pnpm test && nyc report --reporter=text-lcov > coverage.lcov",
"ci:lint": "pnpm build && pnpm lint",
"ci:lint:commits": "commitlint --from=${CIRCLE_BRANCH} --to=${CIRCLE_SHA1}",
"ci:test": "pnpm test -- --verbose && pnpm test:ts",
"prebuild": "del-cli dist",
"prepare": "if [ ! -d 'dist' ]; then pnpm build; fi",
"prerelease": "pnpm build",
"pretest": "pnpm build",
"release": "pnpm --workspace-root plugin:release --pkg $npm_package_name",
"test": "ava",
"test:ts": "tsc types/index.d.ts test/types.ts --noEmit"
},
"files": [
"dist",
"!dist/**/*.map",
"src",
"types",
"README.md"
],
"keywords": [
"rollup",
"plugin",
"esm-shim",
"npm",
"modules"
],
"peerDependencies": {
"rollup": "^2.x || ^3.x"
},
"peerDependenciesMeta": {
"rollup": {
"optional": true
}
},
"dependencies": {
"magic-string": "^0.27.0"
},
"devDependencies": {
"rollup": "^3.0.0-7",
"typescript": "^4.8.3"
},
"types": "./types/index.d.ts"
}
10 changes: 10 additions & 0 deletions packages/esm-shim/rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { readFileSync } from 'node:fs';

import { createConfig } from '../../shared/rollup.config.mjs';

export default {
...createConfig({
pkg: JSON.parse(readFileSync(new URL('./package.json', import.meta.url), { encoding: 'utf-8' }))
}),
input: 'src/index.ts'
};
14 changes: 14 additions & 0 deletions packages/esm-shim/src/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export const CJSyntaxRegex = /__filename|__dirname|require\(|require\.resolve\(/;

export const ESMShim = `
// -- Shims --
import cjsUrl from 'url';
import cjsPath from 'path';
import cjsModule from 'module';
const __filename = cjsUrl.fileURLToPath(import.meta.url);
const __dirname = cjsPath.dirname(__filename);
const require = cjsModule.createRequire(import.meta.url);
`;

export const ESMStaticImportRegex =
/(?<=\s|^|;)import\s*([\s"']*(?<imports>[\w\t\n\r $*,/{}]+)from\s*)?["']\s*(?<specifier>(?<="\s*)[^"]*[^\s"](?=\s*")|(?<='\s*)[^']*[^\s'](?=\s*'))\s*["'][\s;]*/gm;
10 changes: 10 additions & 0 deletions packages/esm-shim/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* Copyright (c) 2023.
* The core of this plugin was conceived by pi0 and is taken from the following repository:
* https://github.com/unjs/unbuild/blob/main/src/builder/plugins/cjs.ts
*/
import { esmShim } from './module';

export * from './types';
export * from './utils';
export default esmShim;
16 changes: 16 additions & 0 deletions packages/esm-shim/src/module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import type { Plugin } from 'rollup';

import { provideCJSSyntax } from './utils';

export function esmShim(): Plugin {
return {
name: 'esm-shim',
renderChunk(code, _chunk, opts) {
if (opts.format === 'es') {
return provideCJSSyntax(code);
}

return null;
}
};
}
6 changes: 6 additions & 0 deletions packages/esm-shim/src/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import type { SourceMapInput } from 'rollup';

export interface Output {
code: string;
map?: SourceMapInput;
}
50 changes: 50 additions & 0 deletions packages/esm-shim/src/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import MagicString from 'magic-string';

// Shim __dirname, __filename and require
import { ESMShim, CJSyntaxRegex, ESMStaticImportRegex } from './constants';
import type { Output } from './types';

function matchAllPolyfill(input: string, pattern: string | RegExp): RegExpMatchArray[] {
const regex = new RegExp(pattern, 'g');
const output: RegExpMatchArray[] = [];

const result = input.match(regex);
if (!result) {
return [];
}

for (let i = 0; i < result.length; i++) {
output.push(result[i].match(new RegExp(pattern)) || []);
}
return output;
}

export function matchAll(regex: RegExp, input: string, addition: Record<string, any>) {
const matches = [];
for (const match of matchAllPolyfill(input, regex)) {
matches.push({
...addition,
...match.groups,
code: match[0],
start: match.index,
end: (match.index || 0) + match[0].length
});
}
return matches;
}

export function provideCJSSyntax(code: string): Output | null {
if (code.includes(ESMShim) || !CJSyntaxRegex.test(code)) {
return null;
}

const lastESMImport = matchAll(ESMStaticImportRegex, code, { type: 'static' }).pop();
const indexToAppend = lastESMImport ? lastESMImport.end : 0;
const s = new MagicString(code);
s.appendRight(indexToAppend, ESMShim);

return {
code: s.toString(),
map: s.generateMap()
};
}
1 change: 1 addition & 0 deletions packages/esm-shim/test/fixtures/child.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const foo = 'bar';
3 changes: 3 additions & 0 deletions packages/esm-shim/test/fixtures/cjs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const child = require('child');

export { child };
Loading