Skip to content

Commit

Permalink
chore(commonjs): adapt to updated dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
lukastaegert committed Jul 31, 2020
1 parent 3364284 commit c2fb584
Show file tree
Hide file tree
Showing 46 changed files with 84 additions and 73 deletions.
6 changes: 3 additions & 3 deletions codecov.yml
Expand Up @@ -5,6 +5,6 @@ coverage:
round: down
range: 70...100
status:
project: 'no'
patch: 'yes'
comment: 'off'
project: "no"
patch: "yes"
comment: "off"
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -7,7 +7,7 @@
"ci:lint": "node scripts/run-changed.js ci:lint",
"ci:test": "node scripts/run-changed.js ci:test",
"lint": "pnpm run lint:docs && npm run lint:json && pnpm run lint:package && node scripts/run-changed.js lint",
"lint:docs": "prettier --single-quote --arrow-parens avoid --write README.md",
"lint:docs": "prettier --single-quote --arrow-parens avoid --trailing-comma none --write README.md",
"lint:js": "eslint scripts util",
"lint:json": "prettier --write tsconfig.*.json codecov.yml pnpm-workspace.yaml",
"lint:package": "prettier --write package.json --plugin=prettier-plugin-package",
Expand Down
2 changes: 1 addition & 1 deletion packages/alias/package.json
Expand Up @@ -22,7 +22,7 @@
"ci:lint:commits": "commitlint --from=${CIRCLE_BRANCH} --to=${CIRCLE_SHA1}",
"ci:test": "pnpm run test -- --verbose",
"lint": "pnpm run lint:js && pnpm run lint:docs && pnpm run lint:package",
"lint:docs": "prettier --single-quote --arrow-parens avoid --write README.md",
"lint:docs": "prettier --single-quote --arrow-parens avoid --trailing-comma none --write README.md",
"lint:js": "eslint --fix --cache src test types --ext .js,.ts",
"lint:package": "prettier --write package.json --plugin=prettier-plugin-package",
"prebuild": "del-cli dist",
Expand Down
6 changes: 2 additions & 4 deletions packages/auto-install/package.json
Expand Up @@ -19,7 +19,7 @@
"ci:lint:commits": "commitlint --from=${CIRCLE_BRANCH} --to=${CIRCLE_SHA1}",
"ci:test": "pnpm run test -- --verbose",
"lint": "pnpm run lint:js && pnpm run lint:docs && pnpm run lint:package",
"lint:docs": "prettier --single-quote --arrow-parens avoid --write README.md",
"lint:docs": "prettier --single-quote --arrow-parens avoid --trailing-comma none --write README.md",
"lint:js": "eslint --fix --cache src test --ext .js,.ts",
"lint:package": "prettier --write package.json --plugin=prettier-plugin-package",
"prebuild": "del-cli dist",
Expand Down Expand Up @@ -54,9 +54,7 @@
},
"types": "types/index.d.ts",
"ava": {
"babel": {
"compileEnhancements": false
},
"babel": true,
"extensions": [
"ts"
],
Expand Down
2 changes: 1 addition & 1 deletion packages/auto-install/test/npm-bare.js
Expand Up @@ -15,7 +15,7 @@ const input = join(cwd, '../input.js');
process.chdir(cwd);

test('npm, bare', async (t) => {
t.timeout(30000);
t.timeout(50000);
await rollup({
input,
output: {
Expand Down
4 changes: 2 additions & 2 deletions packages/auto-install/test/npm.js
Expand Up @@ -17,7 +17,7 @@ const pkgFile = join(cwd, 'package.json');
process.chdir(cwd);

test('invalid manager', (t) => {
t.timeout(30000);
t.timeout(50000);
const error = t.throws(
() =>
rollup({
Expand All @@ -36,7 +36,7 @@ test('invalid manager', (t) => {
});

test('npm', async (t) => {
t.timeout(30000);
t.timeout(50000);
await rollup({
input,
output: {
Expand Down
2 changes: 1 addition & 1 deletion packages/auto-install/test/yarn-bare.js
Expand Up @@ -15,7 +15,7 @@ const input = join(cwd, '../input.js');
process.chdir(cwd);

test('yarn, bare', async (t) => {
t.timeout(30000);
t.timeout(50000);
await rollup({
input,
output: {
Expand Down
2 changes: 1 addition & 1 deletion packages/auto-install/test/yarn.js
Expand Up @@ -15,7 +15,7 @@ const input = join(cwd, '../input.js');
process.chdir(cwd);

test('yarn', async (t) => {
t.timeout(30000);
t.timeout(50000);
await rollup({
input,
output: {
Expand Down
2 changes: 1 addition & 1 deletion packages/babel/package.json
Expand Up @@ -22,7 +22,7 @@
"ci:lint:commits": "commitlint --from=${CIRCLE_BRANCH} --to=${CIRCLE_SHA1}",
"ci:test": "pnpm run test -- --verbose",
"lint": "pnpm run lint:js && pnpm run lint:docs && pnpm run lint:package",
"lint:docs": "prettier --single-quote --arrow-parens avoid --write README.md",
"lint:docs": "prettier --single-quote --arrow-parens avoid --trailing-comma none --write README.md",
"lint:js": "eslint --fix --cache src test",
"lint:package": "prettier --write package.json --plugin=prettier-plugin-package",
"prebuild": "del-cli dist",
Expand Down
2 changes: 1 addition & 1 deletion packages/beep/package.json
Expand Up @@ -20,7 +20,7 @@
"ci:lint:commits": "commitlint --from=${CIRCLE_BRANCH} --to=${CIRCLE_SHA1}",
"ci:test": "ava --verbose",
"lint": "pnpm run lint:js && pnpm run lint:docs && pnpm run lint:package",
"lint:docs": "prettier --single-quote --arrow-parens avoid --write README.md",
"lint:docs": "prettier --single-quote --arrow-parens avoid --trailing-comma none --write README.md",
"lint:js": "eslint --fix --cache lib test types --ext .js,.ts",
"lint:package": "prettier --write package.json --plugin=prettier-plugin-package",
"test": "ava"
Expand Down
2 changes: 1 addition & 1 deletion packages/buble/package.json
Expand Up @@ -22,7 +22,7 @@
"ci:lint:commits": "commitlint --from=${CIRCLE_BRANCH} --to=${CIRCLE_SHA1}",
"ci:test": "pnpm run test -- --verbose",
"lint": "pnpm run lint:js && pnpm run lint:docs && pnpm run lint:package",
"lint:docs": "prettier --single-quote --arrow-parens avoid --write README.md",
"lint:docs": "prettier --single-quote --arrow-parens avoid --trailing-comma none --write README.md",
"lint:js": "eslint --fix --cache src test types --ext .js,.ts",
"lint:package": "prettier --write package.json --plugin=prettier-plugin-package",
"prebuild": "del-cli dist",
Expand Down
60 changes: 33 additions & 27 deletions packages/commonjs/README.md
Expand Up @@ -34,9 +34,9 @@ export default {
input: 'src/index.js',
output: {
dir: 'output',
format: 'cjs'
format: 'cjs',
},
plugins: [commonjs()]
plugins: [commonjs()],
};
```

Expand Down Expand Up @@ -66,8 +66,8 @@ commonjs({
'!node_modules/logform/index.js',
'!node_modules/logform/format.js',
'!node_modules/logform/levels.js',
'!node_modules/logform/browser.js'
]
'!node_modules/logform/browser.js',
],
});
```

Expand Down Expand Up @@ -157,7 +157,7 @@ import * as foo from 'foo';
```

This is in line with how other bundlers handle this situation and is also the most likely behaviour in case Node should ever support this. However there are some situations where this may not be desired:

- There is code in an external dependency that cannot be changed where a `require` statement expects the default export to be returned from an ES module.
- If the imported module is in the same bundle, Rollup will generate a namespace object for the imported module which can increase bundle size unnecessarily:

Expand All @@ -168,15 +168,15 @@ This is in line with how other bundlers handle this situation and is also the mo

// input: dep.js
export default 'foo';

// output
var dep = 'foo';
var dep$1 = /*#__PURE__*/Object.freeze({
__proto__: null,
'default': dep

var dep$1 = /*#__PURE__*/ Object.freeze({
__proto__: null,
default: dep,
});

console.log(dep$1.default);
```

Expand All @@ -191,22 +191,26 @@ For these situations, you can change Rollup's behaviour either globally or per m

// output
import * as dep from 'dep';

console.log(dep);
```

- `"auto"`: This is complementary to how [`output.exports`](https://rollupjs.org/guide/en/#outputexports): `"auto"` works in Rollup: If a module has a default export and no named exports, requiring that module returns the default export. In all other cases, the namespace is returned. For external dependencies when using `esmExternals: true`, a corresponding interop helper is added:

```js
// output
import * as dep$1 from 'dep';

function getDefaultExportFromNamespaceIfNotNamed (n) {
return n && Object.prototype.hasOwnProperty.call(n, 'default') && Object.keys(n).length === 1 ? n['default'] : n;

function getDefaultExportFromNamespaceIfNotNamed(n) {
return n &&
Object.prototype.hasOwnProperty.call(n, 'default') &&
Object.keys(n).length === 1
? n['default']
: n;
}

var dep = getDefaultExportFromNamespaceIfNotNamed(dep$1);

console.log(dep);
```

Expand All @@ -215,13 +219,15 @@ For these situations, you can change Rollup's behaviour either globally or per m
```js
// output
import * as dep$1 from 'dep';

function getDefaultExportFromNamespaceIfPresent (n) {
return n && Object.prototype.hasOwnProperty.call(n, 'default') ? n['default'] : n;

function getDefaultExportFromNamespaceIfPresent(n) {
return n && Object.prototype.hasOwnProperty.call(n, 'default')
? n['default']
: n;
}

var dep = getDefaultExportFromNamespaceIfPresent(dep$1);

console.log(dep);
```

Expand All @@ -230,7 +236,7 @@ For these situations, you can change Rollup's behaviour either globally or per m
```js
// output
import dep from 'dep';

console.log(dep);
```

Expand All @@ -250,9 +256,9 @@ export default {
output: {
file: 'bundle.js',
format: 'iife',
name: 'MyModule'
name: 'MyModule',
},
plugins: [resolve(), commonjs()]
plugins: [resolve(), commonjs()],
};
```

Expand All @@ -262,7 +268,7 @@ Symlinks are common in monorepos and are also created by the `npm link` command.

```js
commonjs({
include: /node_modules/
include: /node_modules/,
});
```

Expand Down
2 changes: 1 addition & 1 deletion packages/commonjs/package.json
Expand Up @@ -22,7 +22,7 @@
"ci:lint:commits": "commitlint --from=${CIRCLE_BRANCH} --to=${CIRCLE_SHA1}",
"ci:test": "pnpm run test -- --verbose && pnpm run test:ts",
"lint": "pnpm run lint:js && pnpm run lint:docs && pnpm run lint:package",
"lint:docs": "prettier --single-quote --arrow-parens avoid --write README.md",
"lint:docs": "prettier --single-quote --arrow-parens avoid --trailing-comma none --write README.md",
"lint:js": "eslint --fix --cache src test types --ext .js,.ts",
"lint:package": "prettier --write package.json --plugin=prettier-plugin-package",
"prebuild": "del-cli dist",
Expand Down
@@ -1,6 +1,7 @@
const externalNamed = require('external-esm-named');
const externalMixed = require('external-esm-mixed');
const externalDefault = require('external-esm-default');

const mixedExports = require('./mixed.js');
const defaultExport = require('./default.js');

Expand Down
@@ -1 +1,3 @@
export * as default from './other.js';
import * as other from './other.js';

export default other;
@@ -1,4 +1,5 @@
import external from 'external-esm-default';

import dep from './dep';

t.is(dep, 'default');
Expand Down
@@ -1,4 +1,5 @@
import external, { foo } from 'external-esm-mixed';

import dep, { named } from './dep';

t.is(dep, 'default');
Expand Down
@@ -1,4 +1,5 @@
import { foo } from 'external-esm-named';

import { named } from './dep';

t.is(named, 'named');
Expand Down
@@ -1,4 +1,5 @@
import * as external from 'external-esm-default';

import * as dep from './dep';

t.deepEqual(dep, {
Expand Down
@@ -1,4 +1,5 @@
import * as external from 'external-esm-mixed';

import * as dep from './dep';

t.deepEqual(dep, {
Expand Down
@@ -1,4 +1,5 @@
import * as external from 'external-esm-named';

import * as dep from './dep';

t.deepEqual(dep, {
Expand Down
6 changes: 3 additions & 3 deletions packages/commonjs/test/snapshots/function.js.md
Expand Up @@ -2,7 +2,7 @@

The actual snapshot is saved in `function.js.snap`.

Generated by [AVA](https://ava.li).
Generated by [AVA](https://avajs.dev).

## assign-properties-to-default-export

Expand Down Expand Up @@ -3917,13 +3917,13 @@ Generated by [AVA](https://ava.li).
const foo = 'foo';␊
var other = 'bar';␊
var dep = /*#__PURE__*/Object.freeze({␊
var other$1 = /*#__PURE__*/Object.freeze({␊
__proto__: null,␊
foo: foo,␊
'default': other␊
});␊
t.deepEqual(dep, { default: 'bar', foo: 'foo' });␊
t.deepEqual(other$1, { default: 'bar', foo: 'foo' });␊
var main = {␊
Expand Down
Binary file modified packages/commonjs/test/snapshots/function.js.snap
Binary file not shown.
2 changes: 1 addition & 1 deletion packages/data-uri/package.json
Expand Up @@ -22,7 +22,7 @@
"ci:lint:commits": "commitlint --from=${CIRCLE_BRANCH} --to=${CIRCLE_SHA1}",
"ci:test": "pnpm run test -- --verbose",
"lint": "pnpm run lint:js && pnpm run lint:docs && pnpm run lint:package",
"lint:docs": "prettier --single-quote --arrow-parens avoid --write README.md",
"lint:docs": "prettier --single-quote --arrow-parens avoid --trailing-comma none --write README.md",
"lint:js": "eslint --fix --cache src test types --ext .js,.ts",
"lint:package": "prettier --write package.json --plugin=prettier-plugin-package",
"prebuild": "del-cli dist",
Expand Down
2 changes: 1 addition & 1 deletion packages/dsv/package.json
Expand Up @@ -19,7 +19,7 @@
"ci:lint:commits": "commitlint --from=${CIRCLE_BRANCH} --to=${CIRCLE_SHA1}",
"ci:test": "pnpm run test -- --verbose",
"lint": "pnpm run lint:js && pnpm run lint:docs && pnpm run lint:package",
"lint:docs": "prettier --single-quote --arrow-parens avoid --write README.md",
"lint:docs": "prettier --single-quote --arrow-parens avoid --trailing-comma none --write README.md",
"lint:js": "eslint --fix --cache src test --ext .js,.ts",
"lint:package": "prettier --write package.json --plugin=prettier-plugin-package",
"prebuild": "del-cli dist",
Expand Down
2 changes: 1 addition & 1 deletion packages/dynamic-import-vars/package.json
Expand Up @@ -22,7 +22,7 @@
"ci:lint:commits": "commitlint --from=${CIRCLE_BRANCH} --to=${CIRCLE_SHA1}",
"ci:test": "pnpm run test -- --verbose",
"lint": "pnpm run lint:js && pnpm run lint:docs && pnpm run lint:package",
"lint:docs": "prettier --single-quote --arrow-parens avoid --write README.md",
"lint:docs": "prettier --single-quote --arrow-parens avoid --trailing-comma none --write README.md",
"lint:js": "eslint --fix --cache src test --ext .js",
"lint:package": "prettier --write package.json --plugin=prettier-plugin-package",
"prebuild": "del-cli dist",
Expand Down
2 changes: 1 addition & 1 deletion packages/html/package.json
Expand Up @@ -20,7 +20,7 @@
"ci:lint:commits": "commitlint --from=${CIRCLE_BRANCH} --to=${CIRCLE_SHA1}",
"ci:test": "pnpm run test -- --verbose",
"lint": "pnpm run lint:js && pnpm run lint:docs && pnpm run lint:package",
"lint:docs": "prettier --single-quote --arrow-parens avoid --write *.md",
"lint:docs": "prettier --single-quote --arrow-parens avoid --trailing-comma none --write *.md",
"lint:js": "eslint --fix --cache lib test --ext .js,.ts",
"lint:package": "prettier --write package.json --plugin=prettier-plugin-package",
"prepublishOnly": "pnpm run lint",
Expand Down
2 changes: 1 addition & 1 deletion packages/image/package.json
Expand Up @@ -22,7 +22,7 @@
"ci:lint:commits": "commitlint --from=${CIRCLE_BRANCH} --to=${CIRCLE_SHA1}",
"ci:test": "pnpm run test -- --verbose",
"lint": "pnpm run lint:js && pnpm run lint:docs && pnpm run lint:package",
"lint:docs": "prettier --single-quote --arrow-parens avoid --write *.md",
"lint:docs": "prettier --single-quote --arrow-parens avoid --trailing-comma none --write *.md",
"lint:js": "eslint --fix --cache src test --ext .js,.ts",
"lint:package": "prettier --write package.json --plugin=prettier-plugin-package",
"prebuild": "del-cli dist",
Expand Down
2 changes: 1 addition & 1 deletion packages/inject/package.json
Expand Up @@ -19,7 +19,7 @@
"ci:lint:commits": "commitlint --from=${CIRCLE_BRANCH} --to=${CIRCLE_SHA1}",
"ci:test": "pnpm run test -- --verbose && pnpm run test:ts",
"lint": "pnpm run lint:js && pnpm run lint:docs && pnpm run lint:package",
"lint:docs": "prettier --single-quote --arrow-parens avoid --write README.md",
"lint:docs": "prettier --single-quote --arrow-parens avoid --trailing-comma none --write README.md",
"lint:js": "eslint --fix --cache src test --ext .js,.ts",
"lint:package": "prettier --write package.json --plugin=prettier-plugin-package",
"prebuild": "del-cli dist",
Expand Down

0 comments on commit c2fb584

Please sign in to comment.