Skip to content

Commit

Permalink
Merge branch 'master' into commonjs-strict-requires-true
Browse files Browse the repository at this point in the history
  • Loading branch information
bluwy committed Sep 23, 2024
2 parents 3d78403 + 28b9701 commit e2d74c0
Show file tree
Hide file tree
Showing 89 changed files with 1,206 additions and 447 deletions.
4 changes: 4 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ packages/typescript/test/fixtures/syntax-error

# temporary workaround for eslint bug where package.json is a directory
packages/node-resolve/test/fixtures/package-json-in-path

# temporary workaround for TypeScript as it doesn't support "Arbitrary module namespace identifier names"
# https://github.com/microsoft/TypeScript/issues/40594
packages/json/test/fixtures/arbitrary/main.js
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

pnpm dlx lint-staged
pnpm exec lint-staged
17 changes: 4 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,23 @@
"lint:js": "eslint --cache packages scripts shared util --ext .js,.ts,.mjs",
"lint:json": "prettier --write .github/**/*.yml **/tsconfig.json tsconfig.*.json pnpm-workspace.yaml",
"lint:package": "prettier --write **/package.json",
"package:release": "versioner --stripShortName='^@.+/plugin-' --target",
"package:release": "versioner --stripShortName='^@.+/(plugin-)?' --target",
"preinstall": "node scripts/disallow-npm.js",
"prepare": "husky install",
"prettier": "prettier --write .",
"prettier:check": "prettier --check .",
"security": "pnpm audit --audit-level=high"
},
"devDependencies": {
"@ava/babel": "2.0.0",
"@dot/versioner": "^0.3.1",
"@rollup/plugin-typescript": "^9.0.1",
"@types/conventional-commits-parser": "^3.0.2",
"@types/node": "14.18.30",
"@types/semver": "^7.3.7",
"@types/source-map-support": "^0.5.4",
"@types/yargs-parser": "^20.2.1",
"@typescript-eslint/eslint-plugin": "^5.38.0",
"@typescript-eslint/parser": "^5.38.0",
"ava": "^4.3.3",
"chalk": "^4.1.0",
"codecov-lite": "2.0.0",
"conventional-commits-parser": "^3.2.1",
"del-cli": "^5.0.0",
"eslint-config-rollup": "^3.0.1",
"esm": "^3.2.25",
Expand All @@ -41,14 +36,9 @@
"nyc": "^15.1.0",
"pnpm": "^8.7.5",
"prettier-plugin-package": "^1.3.0",
"semver": "^7.3.2",
"source-map-support": "^0.5.21",
"ts-node": "10.9.1",
"tsconfig-paths": "^3.9.0",
"typescript": "^4.8.3",
"write-pkg": "^4.0.0",
"yaml": "^1.10.0",
"yargs-parser": "^20.2.9"
"typescript": "^4.8.3"
},
"ava": {
"files": [
Expand Down Expand Up @@ -85,5 +75,6 @@
"lib/client*.js",
"test/"
]
}
},
"packageManager": "[email protected]+sha512.d1a029e1a447ad90bc96cd58b0fad486d2993d531856396f7babf2d83eb1823bb83c5a3d0fc18f675b2d10321d49eb161fece36fe8134aa5823ecd215feed392"
}
8 changes: 8 additions & 0 deletions packages/alias/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# @rollup/plugin-alias ChangeLog

## v5.1.1

_2024-09-22_

### Bugfixes

- fix: remove unused slash dependency (#1763)

## v5.1.0

_2023-11-25_
Expand Down
5 changes: 1 addition & 4 deletions packages/alias/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rollup/plugin-alias",
"version": "5.1.0",
"version": "5.1.1",
"publishConfig": {
"access": "public"
},
Expand Down Expand Up @@ -58,9 +58,6 @@
"optional": true
}
},
"dependencies": {
"slash": "^4.0.0"
},
"devDependencies": {
"@rollup/plugin-node-resolve": "^15.0.0",
"@rollup/plugin-typescript": "^9.0.1",
Expand Down
24 changes: 24 additions & 0 deletions packages/commonjs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,29 @@
# @rollup/plugin-commonjs ChangeLog

## v26.0.1

_2024-06-05_

### Bugfixes

- fix: correct import of glob (04a15b5)

## v26.0.0

_2024-06-05_

### Breaking Changes

- chore!: bump glob's version (#1695)

## v25.0.8

_2024-05-22_

### Bugfixes

- fix: preserve the class body property keys even if they are special keywords (#1688)

## v25.0.7

_2023-10-15_
Expand Down
7 changes: 3 additions & 4 deletions packages/commonjs/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rollup/plugin-commonjs",
"version": "25.0.7",
"version": "26.0.1",
"publishConfig": {
"access": "public"
},
Expand All @@ -21,7 +21,7 @@
"default": "./dist/cjs/index.js"
},
"engines": {
"node": ">=14.0.0"
"node": ">=16.0.0 || 14 >= 14.17"
},
"scripts": {
"build": "rollup -c",
Expand Down Expand Up @@ -65,7 +65,7 @@
"@rollup/pluginutils": "^5.0.1",
"commondir": "^1.0.1",
"estree-walker": "^2.0.2",
"glob": "^8.0.3",
"glob": "^10.4.1",
"is-reference": "1.2.1",
"magic-string": "^0.30.3"
},
Expand All @@ -75,7 +75,6 @@
"locate-character": "^2.0.5",
"require-relative": "^0.8.7",
"rollup": "^4.0.0-24",
"shx": "^0.3.4",
"source-map": "^0.7.4",
"source-map-support": "^0.5.21",
"typescript": "^4.8.3"
Expand Down
6 changes: 4 additions & 2 deletions packages/commonjs/src/dynamic-modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { join, resolve, dirname } from 'path';

import getCommonDir from 'commondir';

import glob from 'glob';
import { glob } from 'glob';

import { getVirtualPathForDynamicRequirePath, normalizePathSlashes } from './utils';

Expand Down Expand Up @@ -41,7 +41,9 @@ export function getDynamicRequireModules(patterns, dynamicRequireRoot) {
isNegated
? dynamicRequireModules.delete(targetPath)
: dynamicRequireModules.set(targetPath, resolvedPath);
for (const path of glob.sync(isNegated ? pattern.substr(1) : pattern)) {
for (const path of glob
.sync(isNegated ? pattern.substr(1) : pattern)
.sort((a, b) => a.localeCompare(b, 'en'))) {
const resolvedPath = resolve(path);
const requirePath = normalizePathSlashes(resolvedPath);
if (isDirectory(resolvedPath)) {
Expand Down
7 changes: 6 additions & 1 deletion packages/commonjs/src/transform-commonjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,12 @@ export default async function transformCommonjs(
return;
case 'Identifier': {
const { name } = node;
if (!isReference(node, parent) || scope.contains(name)) return;
if (
!isReference(node, parent) ||
scope.contains(name) ||
(parent.type === 'PropertyDefinition' && parent.key === node)
)
return;
switch (name) {
case 'require':
uses.require = true;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
description: 'preserve the class body property keys even if they are special keywords',
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class Rollup {
define;
require;
global;
}

exports.Rollup = Rollup;
35 changes: 35 additions & 0 deletions packages/commonjs/test/snapshots/function.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,41 @@ Generated by [AVA](https://avajs.dev).
`,
}

## class-body-property-keys-are-special-keywords

> Snapshot 1
{
'main.js': `'use strict';␊
function getDefaultExportFromCjs (x) {␊
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;␊
}␊
var main$1 = {};␊
var hasRequiredMain;␊
function requireMain () {␊
if (hasRequiredMain) return main$1;␊
hasRequiredMain = 1;␊
class Rollup {␊
define;␊
require;␊
global;␊
}␊
main$1.Rollup = Rollup;␊
return main$1;␊
}␊
var mainExports = requireMain();␊
var main = /*@__PURE__*/getDefaultExportFromCjs(mainExports);␊
module.exports = main;␊
`,
}

## compiled-esm-default-is-module-exports-false

> Snapshot 1
Expand Down
Binary file modified packages/commonjs/test/snapshots/function.js.snap
Binary file not shown.
16 changes: 16 additions & 0 deletions packages/dynamic-import-vars/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
# @rollup/plugin-dynamic-import-vars ChangeLog

## v2.1.3

_2024-09-22_

### Bugfixes

- fix: simplify regex (#1751)

## v2.1.2

_2023-11-28_

### Bugfixes

- fix: Allow a "no files found" error to be emitted as warning (#1625)

## v2.1.1

_2023-11-25_
Expand Down
2 changes: 2 additions & 0 deletions packages/dynamic-import-vars/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ Default: `false`

By default, the plugin will not throw errors when target files are not found. Setting this option to true will result in errors thrown when encountering files which don't exist.

⚠️ _Important:_ Enabling this option when `warnOnError` is set to `true` will result in a warning and _not_ an error

#### `warnOnError`

Type: `Boolean`<br>
Expand Down
2 changes: 1 addition & 1 deletion packages/dynamic-import-vars/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rollup/plugin-dynamic-import-vars",
"version": "2.1.1",
"version": "2.1.3",
"publishConfig": {
"access": "public"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/dynamic-import-vars/src/dynamic-import-to-glob.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export function dynamicImportToGlob(node, sourceString) {
}

// Disallow ./*.ext
const ownDirectoryStarExtension = /^\.\/\*\.[\w]+$/;
const ownDirectoryStarExtension = /^\.\/\*\.\w+$/;
if (ownDirectoryStarExtension.test(glob)) {
throw new VariableDynamicImportError(
`${
Expand Down
11 changes: 7 additions & 4 deletions packages/dynamic-import-vars/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,14 @@ function dynamicImportVariables({ include, exclude, warnOnError, errorWhenNoFile
);

if (errorWhenNoFilesFound && paths.length === 0) {
this.error(
new Error(
`No files found in ${glob} when trying to dynamically load concatted string from ${id}`
)
const error = new Error(
`No files found in ${glob} when trying to dynamically load concatted string from ${id}`
);
if (warnOnError) {
this.warn(error);
} else {
this.error(error);
}
}

// create magic string if it wasn't created already
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ test("doesn't throw if no files in dir when option isn't set", async (t) => {
t.false(thrown);
});

test('throws if no files in dir when option is set', async (t) => {
test('throws if no files in dir when `errorWhenNoFilesFound` is set', async (t) => {
let thrown = false;
try {
await rollup({
Expand All @@ -236,3 +236,21 @@ test('throws if no files in dir when option is set', async (t) => {
}
t.true(thrown);
});

test('warns if no files in dir when `errorWhenNoFilesFound` and `warnOnError` are both set', async (t) => {
let warningEmitted = false;
await rollup({
input: 'fixture-no-files.js',
plugins: [dynamicImportVars({ errorWhenNoFilesFound: true, warnOnError: true })],
onwarn(warning) {
t.deepEqual(
warning.message,
`No files found in ./module-dir-c/*.js when trying to dynamically load concatted string from ${require.resolve(
'./fixtures/fixture-no-files.js'
)}`
);
warningEmitted = true;
}
});
t.true(warningEmitted);
});
16 changes: 16 additions & 0 deletions packages/esm-shim/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
# @rollup/plugin-esm-shim ChangeLog

## v0.1.7

_2024-06-05_

### Bugfixes

- fix: missing exports in types (#1670)

## v0.1.6

_2024-04-05_

### Bugfixes

- fix: do not insert shims at `import` literal (#1696)

## v0.1.5

_2023-11-05_
Expand Down
2 changes: 1 addition & 1 deletion packages/esm-shim/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rollup/plugin-esm-shim",
"version": "0.1.5",
"version": "0.1.7",
"publishConfig": {
"access": "public"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/esm-shim/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ 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;
/(?<=\s|^|;)import\s*([\s"']*(?<imports>[\w\t\n\r $*,/{}]+)from\s*)?["']\s*(?<specifier>(?<="\s*)[^"\n]*[^\s"](?=\s*")|(?<='\s*)[^'\n]*[^\s'](?=\s*'))\s*["'][\s;]*/gm;
6 changes: 6 additions & 0 deletions packages/esm-shim/test/fixtures/cjs-import-literal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const dn = __dirname;

module.exports = {
keyword: ' import',
dn
};
Loading

0 comments on commit e2d74c0

Please sign in to comment.