Skip to content

Commit 4b61b4e

Browse files
committed
Add rollup bundler
1 parent e8bcac5 commit 4b61b4e

7 files changed

+202
-49
lines changed

.npmignore

-3
This file was deleted.

babel.config.js

-29
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,6 @@
1-
/* eslint-disable @typescript-eslint/no-var-requires */
2-
const tsconfig = require('tsconfig');
3-
const fs = require('fs');
4-
const assert = require('assert');
5-
6-
const isTest = process.env.NODE_ENV === 'test';
7-
const filePath = tsconfig.resolveSync('.');
8-
9-
assert(filePath);
10-
11-
// @ts-ignore
12-
const config = tsconfig.readFileSync(filePath);
13-
const baseUrl = config.compilerOptions.baseUrl;
14-
15-
const moduleMappings = fs
16-
.readdirSync(baseUrl, { withFileTypes: true })
17-
.filter(dirent => dirent.isDirectory())
18-
.map(dirent => dirent.name)
19-
.reduce((memo, dir) => ({ ...memo, [dir]: ['./src/', dir].join('') }), {});
20-
211
module.exports = {
222
presets: [
233
['@babel/preset-env', { targets: { node: 'current' } }],
244
'@babel/preset-typescript',
255
],
26-
plugins: [
27-
!isTest && [
28-
'module-resolver',
29-
{
30-
root: ['./src'],
31-
alias: moduleMappings,
32-
},
33-
],
34-
].filter(Boolean),
356
};

package.json

+23-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,22 @@
99
"typescript"
1010
],
1111
"author": "infctr <[email protected]>",
12-
"main": "dist/index.js",
12+
"main": "lib/index.cjs.js",
13+
"module": "lib/index.esm.js",
1314
"repository": "[email protected]:infctr/eslint-plugin-typescript-sort-keys.git",
1415
"url": "https://github.com/infctr/eslint-plugin-typescript-sort-keys",
16+
"files": [
17+
"/lib",
18+
"package.json",
19+
"CHANGELOG.md",
20+
"LICENSE.md",
21+
"README.md"
22+
],
23+
"exports": {
24+
"import": "lib/index.esm.js",
25+
"require": "lib/index.cjs.js",
26+
"default": "lib/index.cjs.js"
27+
},
1528
"scripts": {
1629
"build": "yarn rimraf lib && yarn compile",
1730
"compile": "yarn rollup -c",
@@ -26,6 +39,7 @@
2639
"verify": "yarn type-check && yarn lint && yarn build && yarn test"
2740
},
2841
"dependencies": {
42+
"@typescript-eslint/experimental-utils": "~2.32.0",
2943
"natural-compare-lite": "~1.4.0"
3044
},
3145
"devDependencies": {
@@ -34,16 +48,21 @@
3448
"@babel/preset-env": "~7.9.6",
3549
"@babel/preset-typescript": "~7.9.0",
3650
"@infctr/eslint-docs": "~0.4.0",
51+
"@rollup/plugin-commonjs": "~12.0.0",
52+
"@rollup/plugin-json": "~4.0.3",
53+
"@rollup/plugin-node-resolve": "~8.0.0",
54+
"@rollup/plugin-typescript": "~4.1.2",
55+
"@types/babel__core": "~7.1.7",
56+
"@types/babel__preset-env": "~7.9.0",
3757
"@types/eslint": "~6.8.1",
3858
"@types/eslint-plugin-prettier": "~3.1.0",
59+
"@types/http-server": "~0.10.0",
3960
"@types/jest": "~25.2.3",
4061
"@types/natural-compare-lite": "~1.4.0",
4162
"@types/prettier": "~2.0.0",
42-
"@types/requireindex": "~1.2.0",
4363
"@types/rimraf": "~3.0.0",
4464
"@types/tmp": "~0.2.0",
4565
"@typescript-eslint/eslint-plugin": "~2.32.0",
46-
"@typescript-eslint/experimental-utils": "~2.32.0",
4766
"@typescript-eslint/parser": "~2.32.0",
4867
"babel-jest": "~26.0.1",
4968
"babel-plugin-module-resolver": "~4.0.0",
@@ -60,6 +79,7 @@
6079
"lint-staged": "~10.2.4",
6180
"prettier": "~2.0.5",
6281
"rimraf": "~3.0.2",
82+
"rollup": "~2.10.5",
6383
"tmp": "~0.2.1",
6484
"tsconfig": "~7.0.0",
6585
"typescript": "~3.9.3"

rollup.config.js

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import commonjs from '@rollup/plugin-commonjs';
2+
import resolve from '@rollup/plugin-node-resolve';
3+
import typescript from '@rollup/plugin-typescript';
4+
import json from '@rollup/plugin-json';
5+
import tsconfig from 'tsconfig';
6+
import fs from 'fs';
7+
import assert from 'assert';
8+
9+
const filePath = tsconfig.resolveSync('.');
10+
11+
assert(filePath);
12+
13+
const config = tsconfig.readFileSync(filePath);
14+
const baseUrl = config.compilerOptions.baseUrl;
15+
16+
const moduleMappings = fs
17+
.readdirSync(baseUrl, { withFileTypes: true })
18+
.filter(dir => dir.isDirectory())
19+
.map(dir => [dir.name, '/'].join(''));
20+
21+
const external = id =>
22+
!id.startsWith('.') &&
23+
!id.startsWith('/') &&
24+
!id.startsWith('\0') &&
25+
!moduleMappings.some(mapping => id.startsWith(mapping));
26+
27+
export default [
28+
{
29+
input: './src/index.ts',
30+
external,
31+
output: [
32+
{ dir: 'lib', entryFileNames: '[name].cjs.js', format: 'cjs' },
33+
{ dir: 'lib', entryFileNames: '[name].esm.js', format: 'es' },
34+
],
35+
plugins: [commonjs(), resolve(), typescript(), json()],
36+
},
37+
];

tsconfig.build.json

-4
This file was deleted.

tsconfig.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@
33
/* Basic Options */
44
// "incremental": true, /* Enable incremental compilation */
55
"target": "ES6" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */,
6-
"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */,
6+
"module": "esnext" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */,
77
"lib": ["ESNext"] /* Specify library files to be included in the compilation. */,
88
"allowJs": true /* Allow javascript files to be compiled. */,
99
"checkJs": false /* Report errors in .js files. */,
1010
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
11-
"declaration": true /* Generates corresponding '.d.ts' file. */,
11+
// "declaration": true /* Generates corresponding '.d.ts' file. */,
1212
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
1313
"sourceMap": true /* Generates corresponding '.map' file. */,
1414
// "outFile": "./", /* Concatenate and emit output to single file. */
15-
"outDir": "build" /* Redirect output structure to the directory. */,
15+
"outDir": "lib" /* Redirect output structure to the directory. */,
1616
// "rootDir": "src" /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */,
1717
// "composite": true, /* Enable project compilation */
1818
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */

0 commit comments

Comments
 (0)