Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into refactor/use-repl…
Browse files Browse the repository at this point in the history
…ace-test-with-includes
  • Loading branch information
shellscape committed Dec 15, 2024
2 parents 831b717 + 118d463 commit 7862b7e
Show file tree
Hide file tree
Showing 25 changed files with 256 additions and 69 deletions.
16 changes: 16 additions & 0 deletions packages/commonjs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
# @rollup/plugin-commonjs ChangeLog

## v28.0.2

_2024-12-15_

### Updates

- docs: `output.exports` recommendation also applies to IIFE (#1810)

## v28.0.1

_2024-10-16_

### Updates

- chore: upgrade picomatch (#1775)

## v28.0.0

_2024-09-23_
Expand Down
2 changes: 1 addition & 1 deletion packages/commonjs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ export default {
};
```

When bundling to CommonJS, i.e `output.format === 'cjs'`, make sure that you do not set `output.exports` to `'named'`. The default value of `'auto'` will usually work, but you can also set it explicitly to `'default'`. That makes sure that Rollup assigns the default export that was generated for your CommonJS entry point to `module.exports`, and semantics do not change.
When bundling to CommonJS or IIFE, i.e `output.format === 'cjs'` / `output.format === 'iife'`, make sure that you do not set `output.exports` to `'named'`. The default value of `'auto'` will usually work, but you can also set it explicitly to `'default'`. That makes sure that Rollup assigns the default export that was generated for your CommonJS entry point to `module.exports`, and semantics do not change.

## Using with @rollup/plugin-node-resolve

Expand Down
6 changes: 3 additions & 3 deletions packages/commonjs/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rollup/plugin-commonjs",
"version": "28.0.0",
"version": "28.0.2",
"publishConfig": {
"access": "public"
},
Expand Down Expand Up @@ -65,10 +65,10 @@
"@rollup/pluginutils": "^5.0.1",
"commondir": "^1.0.1",
"estree-walker": "^2.0.2",
"fdir": "^6.1.1",
"fdir": "^6.2.0",
"is-reference": "1.2.1",
"magic-string": "^0.30.3",
"picomatch": "^2.3.1"
"picomatch": "^4.0.2"
},
"devDependencies": {
"@rollup/plugin-json": "^5.0.0",
Expand Down
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.5

_2024-10-21_

### Updates

- chore: revert 2.1.4 changes (#1799)

## v2.1.4

_2024-10-16_

### Updates

- chore: switch to tinyglobby for fewer dependencies (#1780)

## v2.1.3

_2024-09-22_
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.3",
"version": "2.1.5",
"publishConfig": {
"access": "public"
},
Expand Down
16 changes: 16 additions & 0 deletions packages/html/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
# @rollup/plugin-html ChangeLog

## v1.1.0

_2024-12-15_

### Features

- feat: implement scripts on head tag (#1816)

## v1.0.5

_2024-12-15_

### Bugfixes

- fix: types for plugin (#1264)

## v1.0.4

_2024-09-22_
Expand Down
7 changes: 7 additions & 0 deletions packages/html/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ Once run successfully, an HTML file should be written to the bundle output desti

## Options

### `addScriptsToHead`

Type: `Boolean`<br>
Default: `false`

Place scripts in the `<head>` tag instead of `<body>`.

### `attributes`

Type: `Object`<br>
Expand Down
2 changes: 1 addition & 1 deletion packages/html/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rollup/plugin-html",
"version": "1.0.4",
"version": "1.1.0",
"publishConfig": {
"access": "public"
},
Expand Down
9 changes: 7 additions & 2 deletions packages/html/recipes/external-files/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
* @param {Array} externals List of external files.
* The format is: [{ type: 'js', file: '//xxxx1.js', pos: 'before' }, { type: 'css', file: '//xxxx1.css' }]
*
* @return {Function} The templae method required by plugin-html
* @return {Function} The template method required by plugin-html
*/
export default function htmlTemplate(externals) {
return ({ attributes, files, meta, publicPath, title }) => {
return ({ attributes, files, meta, publicPath, title, addScriptsToHead }) => {
let scripts = [...(files.js || [])];
let links = [...(files.css || [])];

Expand Down Expand Up @@ -43,6 +43,11 @@ export default function htmlTemplate(externals) {
})
.join('\n');

if (addScriptsToHead === true) {
links += scripts;
scripts = '';
}

const metas = meta
.map((input) => {
const attrs = makeHtmlAttributes(input);
Expand Down
32 changes: 22 additions & 10 deletions packages/html/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,28 @@ const defaultTemplate = async ({
files,
meta,
publicPath,
title
title,
addScriptsToHead
}: RollupHtmlTemplateOptions) => {
const scripts = (files.js || [])
let scripts = (files.js || [])
.map(({ fileName }) => {
const attrs = makeHtmlAttributes(attributes.script);
return `<script src="${publicPath}${fileName}"${attrs}></script>`;
})
.join('\n');

const links = (files.css || [])
let links = (files.css || [])
.map(({ fileName }) => {
const attrs = makeHtmlAttributes(attributes.link);
return `<link href="${publicPath}${fileName}" rel="stylesheet"${attrs}>`;
})
.join('\n');

if (addScriptsToHead === true) {
links += scripts;
scripts = '';
}

const metas = meta
.map((input) => {
const attrs = makeHtmlAttributes(input);
Expand All @@ -70,7 +76,7 @@ const defaultTemplate = async ({

const supportedFormats = ['es', 'esm', 'iife', 'umd'];

const defaults = {
const defaults: Required<RollupHtmlOptions> = {
attributes: {
link: null,
html: { lang: 'en' },
Expand All @@ -80,15 +86,20 @@ const defaults = {
meta: [{ charset: 'utf-8' }],
publicPath: '',
template: defaultTemplate,
title: 'Rollup Bundle'
title: 'Rollup Bundle',
addScriptsToHead: false
};

export default function html(opts: RollupHtmlOptions = {}): Plugin {
const { attributes, fileName, meta, publicPath, template, title } = Object.assign(
{},
defaults,
opts
);
const {
addScriptsToHead,
attributes,
fileName,
meta,
publicPath,
template,
title
}: Required<RollupHtmlOptions> = Object.assign({}, defaults, opts);

return {
name: 'html',
Expand All @@ -113,6 +124,7 @@ export default function html(opts: RollupHtmlOptions = {}): Plugin {
const files = getFiles(bundle);
const source = await template({
attributes,
addScriptsToHead,
bundle,
files,
meta,
Expand Down
46 changes: 46 additions & 0 deletions packages/html/test/snapshots/test.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -353,3 +353,49 @@ Generated by [AVA](https://avajs.dev).
source: '<html><body><main></main></body></html>',
},
]

## scripts on head

> Snapshot 1
[
{
code: `(function (factory) {␊
typeof define === 'function' && define.amd ? define(factory) :␊
factory();␊
})((function () { 'use strict';␊
}));␊
`,
fileName: 'joker.js',
map: null,
source: undefined,
},
{
code: undefined,
fileName: 'joker.css',
map: undefined,
source: Buffer @Uint8Array [
2a207b20 77696474 683a2031 3030253b 207d0a
],
},
{
code: undefined,
fileName: 'index.html',
map: undefined,
source: `␊
<!doctype html>␊
<html>␊
<head>␊
<meta charset="utf-8">␊
<title>Rollup Bundle</title>␊
<link href="joker.css" rel="stylesheet"><script src="joker.js" defer="true"></script>␊
</head>␊
<body>␊
</body>␊
</html>`,
},
]
Binary file modified packages/html/test/snapshots/test.js.snap
Binary file not shown.
17 changes: 17 additions & 0 deletions packages/html/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,20 @@ test.serial('template', async (t) => {
const code = await getCode(bundle, output, true);
t.snapshot(code);
});

test.serial('scripts on head', async (t) => {
const bundle = await rollup({
input: 'joker.js',
plugins: [
css({ extract: true }),
html({
attributes: {
script: { defer: true }
},
addScriptsToHead: true
})
]
});
const code = await getCode(bundle, output, true);
t.snapshot(code);
});
12 changes: 7 additions & 5 deletions packages/html/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
import type { Plugin, OutputChunk, OutputAsset, OutputBundle } from 'rollup';

export interface RollupHtmlTemplateOptions {
title: string;
addScriptsToHead?: boolean;
attributes: Record<string, any>;
publicPath: string;
meta: Record<string, any>[];
bundle: OutputBundle;
files: Record<string, (OutputChunk | OutputAsset)[]>;
meta: Record<string, any>[];
publicPath: string;
title: string;
}

export interface RollupHtmlOptions {
title?: string;
addScriptsToHead?: boolean;
attributes?: Record<string, any>;
fileName?: string;
meta?: Record<string, any>[];
publicPath?: string;
template?: (templateoptions: RollupHtmlTemplateOptions) => string;
template?: (templateoptions: RollupHtmlTemplateOptions) => string | Promise<string>;
title?: string;
}

export function makeHtmlAttributes(attributes: Record<string, string>): string;
Expand Down
8 changes: 8 additions & 0 deletions packages/pluginutils/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# @rollup/pluginutils ChangeLog

## v5.1.3

_2024-10-23_

### Bugfixes

- fix: upgrade picomatch (#1796)

## v5.1.2

_2024-09-23_
Expand Down
4 changes: 2 additions & 2 deletions packages/pluginutils/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rollup/pluginutils",
"version": "5.1.2",
"version": "5.1.3",
"publishConfig": {
"access": "public"
},
Expand Down Expand Up @@ -63,7 +63,7 @@
"dependencies": {
"@types/estree": "^1.0.0",
"estree-walker": "^2.0.2",
"picomatch": "^2.3.1"
"picomatch": "^4.0.2"
},
"devDependencies": {
"@rollup/plugin-commonjs": "^23.0.0",
Expand Down
8 changes: 8 additions & 0 deletions packages/replace/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# @rollup/plugin-replace ChangeLog

## v6.0.2

_2024-12-15_

### Bugfixes

- fix: add missing types for `objectGuards` option (#1818)

## v6.0.1

_2024-09-23_
Expand Down
2 changes: 1 addition & 1 deletion packages/replace/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rollup/plugin-replace",
"version": "6.0.1",
"version": "6.0.2",
"publishConfig": {
"access": "public"
},
Expand Down
1 change: 1 addition & 0 deletions packages/replace/test/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const config: RollupOptions = {
include: 'config.js',
exclude: 'node_modules/**',
delimiters: ['<@', '@>'],
objectGuards: true,
preventAssignment: true,
VERSION: '1.0.0',
ENVIRONMENT: JSON.stringify('development'),
Expand Down
Loading

0 comments on commit 7862b7e

Please sign in to comment.