@pob/rollup-esbuild 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,15 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+ See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
+
6
+ ## 1.0.0 (2024-04-21)
7
+
8
+
9
+ ### Features
10
+
11
+ * add rollup-esbuild ([a1085db](https://github.com/christophehurpeau/pob/commit/a1085dbe6ea69767596dd46813044b96fbf713dd))
12
+
13
+ Version bump for dependency: rollup
14
+
15
+
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 Christophe Hurpeau <christophe@hurpeau.com> (https://christophe.hurpeau.com)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,37 @@
1
+ <h3 align="center">
2
+ @pob/rollup-esbuild
3
+ </h3>
4
+
5
+ <p align="center">
6
+ rollup configuration with typescript for pob
7
+ </p>
8
+
9
+ <p align="center">
10
+ <a href="https://npmjs.org/package/@pob/rollup-esbuild"><img src="https://img.shields.io/npm/v/@pob/rollup-esbuild.svg?style=flat-square"></a>
11
+ <a href="https://npmjs.org/package/@pob/rollup-esbuild"><img src="https://img.shields.io/npm/dw/@pob/rollup-esbuild.svg?style=flat-square"></a>
12
+ <a href="https://npmjs.org/package/@pob/rollup-esbuild"><img src="https://img.shields.io/node/v/@pob/rollup-esbuild.svg?style=flat-square"></a>
13
+ <a href="https://npmjs.org/package/@pob/rollup-esbuild"><img src="https://img.shields.io/npm/types/@pob/rollup-esbuild.svg?style=flat-square"></a>
14
+ </p>
15
+
16
+ ## Install
17
+
18
+ ```bash
19
+ npm install --save rollup-esbuild
20
+ ```
21
+
22
+ ## Usage
23
+
24
+ ```js
25
+ import { dirname } from 'node:path';
26
+ import { fileURLToPath } from 'node:url';
27
+ import createRollupConfig from '@pob/rollup-esbuild/createRollupConfig.js';
28
+ import run from '@pob/rollup-esbuild/plugin-run.cjs';
29
+
30
+ const watch = process.env.ROLLUP_WATCH === 'true';
31
+
32
+ export default createRollupConfig({
33
+ cwd: dirname(fileURLToPath(import.meta.url)),
34
+ outDirectory: 'build',
35
+ plugins: [watch && run({ execArgv: ['--enable-source-maps'] })],
36
+ });
37
+ ```
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+
3
+ import '@pob/rollup/bin/pob-rollup-clean-out.js';
package/bin/rollup.cjs ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env node
2
+
3
+ 'use strict';
4
+
5
+ require('rollup/dist/bin/rollup');
@@ -0,0 +1 @@
1
+ export { default } from './lib/createRollupConfig.js';
@@ -0,0 +1,20 @@
1
+ {
2
+ "root": true,
3
+ "extends": ["@pob/eslint-config/node-module"],
4
+ "overrides": [
5
+ {
6
+ "files": ["**/*.test.{cjs,js}", "__tests__/**/*.{cjs,js}"],
7
+ "env": {
8
+ "jest": true
9
+ },
10
+ "rules": {
11
+ "import/no-extraneous-dependencies": [
12
+ "error",
13
+ {
14
+ "devDependencies": true
15
+ }
16
+ ]
17
+ }
18
+ }
19
+ ]
20
+ }
@@ -0,0 +1,86 @@
1
+ import { readFileSync } from 'node:fs';
2
+ import path from 'node:path';
3
+ import { nodeFormatToExt, resolveEntry } from '@pob/rollup';
4
+ import { nodeResolve } from '@rollup/plugin-node-resolve';
5
+ import configExternalDependencies from 'rollup-config-external-dependencies';
6
+ import esbuild from 'rollup-plugin-esbuild';
7
+
8
+ export default function createRollupConfig({
9
+ cwd = process.cwd(),
10
+ outDirectory = 'dist',
11
+ pkg = JSON.parse(readFileSync(path.join(cwd, 'package.json'))),
12
+ plugins = [],
13
+ }) {
14
+ const pobConfig = pkg.pob;
15
+
16
+ if (pobConfig.babelEnvs) {
17
+ throw new Error(
18
+ '@pob/rollup-esbuild does not supports babel, use `pob-babel` package instead.',
19
+ );
20
+ }
21
+
22
+ const jsx = pobConfig.jsx;
23
+ const externalByPackageJson = configExternalDependencies(pkg);
24
+
25
+ const createConfigForEnv = (entry, entryPath, env) => {
26
+ const extensions = ['.ts', jsx && '.tsx', '.json'].filter(Boolean);
27
+ const preferConst = true;
28
+
29
+ return {
30
+ input: entryPath,
31
+ output: (env.formats || ['es']).map((format) => ({
32
+ file: path.relative(
33
+ process.cwd(),
34
+ path.join(
35
+ cwd,
36
+ `${outDirectory}/${entry}-${env.target}${
37
+ env.omitVersionInFileName ? '' : env.version || ''
38
+ }${
39
+ env.target === 'node'
40
+ ? nodeFormatToExt(format, pkg.type)
41
+ : `.${format}.js`
42
+ }`,
43
+ ),
44
+ ),
45
+ format,
46
+ sourcemap: true,
47
+ exports: 'named',
48
+ generatedCode: {
49
+ constBindings: preferConst,
50
+ },
51
+ externalLiveBindings: false,
52
+ freeze: false,
53
+ })),
54
+ external: externalByPackageJson,
55
+ plugins: [
56
+ esbuild({
57
+ sourceMap: true,
58
+ minify: false,
59
+ tsconfig: path.resolve(cwd, env.tsconfig || 'tsconfig.json'),
60
+ }),
61
+
62
+ nodeResolve({
63
+ extensions,
64
+ customResolveOptions: {
65
+ moduleDirectories: ['src'], // don't resolve node_modules, but allow src (see baseUrl in tsconfig)
66
+ },
67
+ }),
68
+
69
+ ...plugins,
70
+ ].filter(Boolean),
71
+ };
72
+ };
73
+
74
+ return pobConfig.entries.flatMap((entry) => {
75
+ const entryName = typeof entry === 'string' ? entry : entry.name;
76
+ const envs = entry.envs ||
77
+ pobConfig.envs || [
78
+ {
79
+ target: 'node',
80
+ version: '18',
81
+ },
82
+ ];
83
+ const entryPath = resolveEntry(cwd, entryName);
84
+ return envs.map((env) => createConfigForEnv(entryName, entryPath, env));
85
+ });
86
+ }
package/package.json ADDED
@@ -0,0 +1,65 @@
1
+ {
2
+ "name": "@pob/rollup-esbuild",
3
+ "version": "1.0.0",
4
+ "description": "rollup configuration with typescript for pob",
5
+ "keywords": [],
6
+ "author": "Christophe Hurpeau <christophe@hurpeau.com> (https://christophe.hurpeau.com)",
7
+ "license": "MIT",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "https://github.com/christophehurpeau/pob.git",
11
+ "directory": "@pob/rollup-esbuild"
12
+ },
13
+ "homepage": "https://github.com/christophehurpeau/pob",
14
+ "type": "module",
15
+ "engines": {
16
+ "node": ">=18.12.0"
17
+ },
18
+ "sideEffects": false,
19
+ "bin": {
20
+ "pob-esbuild-clean-out": "./bin/pob-esbuild-clean-out.js",
21
+ "rollup": "./bin/rollup.cjs"
22
+ },
23
+ "main": "./lib/index.js",
24
+ "exports": {
25
+ ".": "./lib/index.js",
26
+ "./createRollupConfig": "./createRollupConfig.js",
27
+ "./createRollupConfig.js": "./createRollupConfig.js",
28
+ "./plugin-run": "./plugin-run.cjs",
29
+ "./plugin-run.cjs": "./plugin-run.cjs",
30
+ "./package.json": "./package.json"
31
+ },
32
+ "publishConfig": {
33
+ "access": "public"
34
+ },
35
+ "files": [
36
+ "lib",
37
+ "bin",
38
+ "createRollupConfig.js",
39
+ "plugin-run.cjs"
40
+ ],
41
+ "scripts": {
42
+ "lint": "yarn run lint:eslint",
43
+ "lint:eslint": "yarn ../.. run eslint --report-unused-disable-directives --resolve-plugins-relative-to . --quiet @pob/rollup-esbuild"
44
+ },
45
+ "pob": {},
46
+ "prettier": "@pob/root/prettier-config",
47
+ "peerDependencies": {
48
+ "rollup": "3.29.4",
49
+ "typescript": "^4.0.3 || ^5.0.0"
50
+ },
51
+ "peerDependenciesMeta": {
52
+ "rollup": {
53
+ "optional": true
54
+ }
55
+ },
56
+ "dependencies": {
57
+ "@pob/rollup": "1.1.0",
58
+ "@rollup/plugin-node-resolve": "15.2.3",
59
+ "@rollup/plugin-run": "3.0.2",
60
+ "esbuild": "0.20.2",
61
+ "rollup": "3.29.4",
62
+ "rollup-config-external-dependencies": "^3.0.0",
63
+ "rollup-plugin-esbuild": "6.1.1"
64
+ }
65
+ }
package/plugin-run.cjs ADDED
@@ -0,0 +1,3 @@
1
+ 'use strict';
2
+
3
+ module.exports = require('@rollup/plugin-run');