Skip to content

Commit f8bed8f

Browse files
committed
chore: add some compatibility configs
1 parent 67169b6 commit f8bed8f

16 files changed

+435
-171
lines changed

.fssrc.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import progressPlugin from 'rollup-plugin-progress'
2-
import typescript from 'rollup-plugin-typescript'
3-
import { eslint } from 'rollup-plugin-eslint'
2+
import typescript from '@rollup/plugin-typescript'
3+
import eslint from '@rollup/plugin-eslint'
44

55
import { name, version, license, author, description, dependencies } from './package.json'
66

@@ -33,15 +33,15 @@ export default {
3333
entry: [
3434
{
3535
input: 'src/index.ts',
36-
plugins: [ 'resolve', [typescript], 'commonjs', eslint, progress ],
36+
plugins: [ 'resolve', [typescript], 'commonjs', /* eslint, */ progress ],
3737
output: [
3838
{ file: 'lib/rollup-worker.js', format: 'cjs', banner: banner(name, true) },
3939
{ file: 'lib/rollup-worker.es.js', format: 'es', banner: banner(name, true) }
4040
]
4141
},
4242
{
4343
input: 'src/bin/cli.ts',
44-
plugins: [ 'resolve', [typescript], 'commonjs', eslint, progress ],
44+
plugins: [ 'resolve', [typescript], 'commonjs', /* eslint, */ progress ],
4545
output: [
4646
{
4747
file: 'bin/cli.js',

package.json

+4-5
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,12 @@
4444
"@rollup/plugin-eslint": "^8.0.1",
4545
"@rollup/plugin-node-resolve": "^13",
4646
"@rollup/plugin-replace": "^2",
47+
"@rollup/plugin-typescript": "^11",
4748
"autoprefixer": "^9",
4849
"babel-plugin-macros": "^2.7.0",
4950
"babel-plugin-transform-async-to-promises": "^0.8.15",
5051
"babel-plugin-transform-replace-expressions": "^0.2.0",
51-
"chalk": "^2.4.1",
52+
"colorette": "^2.0.20",
5253
"cssnano": "^4",
5354
"debug": "^3.1.0",
5455
"postcss": "^8.x",
@@ -58,20 +59,18 @@
5859
"rollup-plugin-jspacker": "^1",
5960
"rollup-plugin-node-builtins": "^2",
6061
"rollup-plugin-postcss": "^4",
61-
"rollup-plugin-progress": "^1",
62-
"rollup-plugin-typescript2": "^0"
62+
"rollup-plugin-progress": "^1"
6363
},
6464
"devDependencies": {
6565
"@fdio/utils": "^1",
66-
"@rollup/plugin-typescript": "^8",
6766
"ansi-escapes": "^3.1.0",
6867
"babel-plugin-alter-object-assign": "^1.0.2",
6968
"date-time": "^2.1.0",
7069
"mkdirp": "^0.5.1",
7170
"pretty-bytes": "^5.1.0",
7271
"pretty-ms": "^3.1.0",
7372
"signal-exit": "^3.0.2",
74-
"tslib": "^1.9.3",
73+
"tslib": "^2",
7574
"tslint": "^5.12.1"
7675
},
7776
"eslintIgnore": [

src/bin/cli.ts

+2-12
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import p from 'path'
55
import { Bundler, loadConfigFile, version } from '../index'
66

77
import { relativeId } from '../utils'
8-
import { stderr } from '../utils/logging'
8+
import { handleError, stderr } from '../utils/logging'
99

1010
import watch from './watch'
1111

@@ -130,16 +130,6 @@ loadConfigFile(configFile)
130130
return build(configs)
131131
}
132132
})
133-
.catch(e => fatal(e))
134-
135-
function fatal (err) {
136-
let msg = err
137-
if (err instanceof Error) {
138-
msg = `ERROR: ${err.message}`
139-
msg += `${msg[msg.length - 1] === '\n' ? '' : '\n'}${err.stack.trimStart('\n')}`
140-
}
141-
stderr(msg)
142-
process.exit(1)
143-
}
133+
.catch(e => handleError(e, true))
144134

145135
export { build, watch }

src/bin/timings.ts

+9-8
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
import tc from 'chalk'
21
import prettyBytes from 'pretty-bytes'
2+
import { SerializedTimings } from 'rollup'
33

4-
export function printTimings (timings) {
5-
Object.keys(timings).forEach(label => {
6-
const color =
7-
label[0] === '#' ? (label[1] !== '#' ? tc.underline : tc.bold) : text => text
8-
const [time, memory, total] = timings[label]
9-
const row: any = `${label}: ${time.toFixed(0)}ms, ${prettyBytes(memory)} / ${prettyBytes(total)}`
10-
console.info(color(row)) // eslint-disable-line no-console
4+
import { bold, underline } from '../utils/colors'
5+
6+
export function printTimings (timings: SerializedTimings): void {
7+
Object.entries(timings).forEach(([label, [time, memory, total]]) => {
8+
const appliedColor =
9+
label[0] === '#' ? (label[1] !== '#' ? underline : bold) : (text: string) => text
10+
const row = `${label}: ${time.toFixed(0)}ms, ${prettyBytes(memory)} / ${prettyBytes(total)}`
11+
console.info(appliedColor(row))
1112
})
1213
}

src/bin/watch.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import chalk from 'chalk'
21
import dateTime from 'date-time'
32
import prettyMs from 'pretty-ms'
43
import signalExit from 'signal-exit'
54

65
import { Bundler, version } from '../index'
76
import { relativeId } from '../utils'
87
import batchWarnings from '../utils/batchWarnings'
8+
import { bold, cyan, green, underline } from '../utils/colors'
99
import { handleError, stderr } from '../utils/logging'
1010

1111
import alternateScreen from './alternateScreen'
@@ -30,7 +30,7 @@ function watch (configFile: string, configs: {}, silent = false) {
3030
let watcher
3131

3232
function start (configs) {
33-
screen.reset(chalk.underline('rollup-worker v' + version))
33+
screen.reset(underline('rollup-worker v' + version))
3434
const screenWriter = configs.processConfigsErr || screen.reset
3535
watcher = new Bundler(configs).watch()
3636
watcher.on('event', event => {
@@ -45,7 +45,7 @@ function watch (configFile: string, configs: {}, silent = false) {
4545
handleError(event.error, true)
4646
break
4747
case 'START':
48-
screenWriter(chalk.underline('rollup-worker v' + version))
48+
screenWriter(underline('rollup-worker v' + version))
4949
break
5050
case 'BUNDLE_START':
5151
if (!silent) {
@@ -57,12 +57,12 @@ function watch (configFile: string, configs: {}, silent = false) {
5757
.map(key => input[key])
5858
.join(', ')
5959
}
60-
stderr(chalk.cyan(`bundles ${chalk.bold(relativeId(input))} \u2192 ${chalk.bold(event.output.map(relativeId).join(', '))}...`))
60+
stderr(cyan(`bundles ${bold(relativeId(input))} \u2192 ${bold(event.output.map(relativeId).join(', '))}...`))
6161
}
6262
break
6363
case 'BUNDLE_END':
6464
warnings.flush()
65-
if (!silent) { stderr(chalk.green(`created ${chalk.bold(event.output.map(relativeId).join(', '))} in ${chalk.bold(prettyMs(event.duration))}`)) }
65+
if (!silent) { stderr(green(`created ${bold(event.output.map(relativeId).join(', '))} in ${bold(prettyMs(event.duration))}`)) }
6666
if (event.result && event.result.getTimings) {
6767
printTimings(event.result.getTimings())
6868
}

src/index.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
* Allex Wang <[email protected]> (http://iallex.com/)
88
*/
99

10-
import chalk from 'chalk'
1110
import Debug from 'debug'
1211
import { basename, resolve } from 'path'
1312
import prettyBytes from 'pretty-bytes'
@@ -22,15 +21,15 @@ import { buildPlugin } from './plugins'
2221
import { mergeArray, relativeId } from './utils'
2322
import { stderr } from './utils/logging'
2423

24+
import { bold, cyan, green } from './utils/colors'
2525
import configLoader from './utils/configLoader'
2626

2727
export { version } from '../package.json'
2828
export { loadConfigFile } from './loadConfigFile'
2929

3030
export interface BundlerEntry {
3131
input: InputOption;
32-
targets?: OutputOptions; // deprecated
33-
output: OutputOptions;
32+
output: OutputOptions[];
3433
plugins: Kv;
3534
globals: Kv;
3635
external: (id: string, format: string, defaultFn: any) => boolean | Kv<string>;
@@ -78,6 +77,8 @@ export interface RollupContext extends InputOptions {
7877
export class Bundler {
7978
config: BundlerOptions
8079

80+
rootDir: string
81+
8182
/**
8283
* Multi-entry config for rollup bundle
8384
*
@@ -164,13 +165,12 @@ export class Bundler {
164165
_normalizeEntry (entry: BundlerEntry): Array<{ i: InputOptions; o: OutputOptions; }> {
165166
const destDir = this.config.destDir
166167
const {
167-
targets, // `targets` be deprecated, use output instead
168168
output,
169169
globals = {},
170170
...baseInput
171171
} = entry
172172

173-
let chunks = output || targets
173+
let chunks: OutputOptions[] = output
174174
if (!chunks) {
175175
throw new Error('`output` mandatory required')
176176
}
@@ -301,14 +301,14 @@ export class Bundler {
301301

302302
debug('entries (normalized) => \n%O', list)
303303

304-
stderr(chalk.cyan(`build ${chalk.bold(relativeId(entry.input))} \u2192 ${chalk.bold(files.join(', '))} ...`))
304+
stderr(cyan(`build ${bold(relativeId(entry.input))} \u2192 ${bold(files.join(', '))} ...`))
305305

306306
return sequence(list, async ({ i, o }): Promise<RollupBuild> => {
307307
const start = Date.now()
308308
const bundle: RollupBuild = await rollup.rollup(i)
309309
const out: RollupOutput = await bundle.write(o)
310310

311-
stderr(chalk.green(`created ${chalk.bold(relativeId(o.file || o.dir))} (${prettyBytes(out.output.filter(o => o.code).reduce((n, o) => n + o.code.length, 0))}) in ${chalk.bold(prettyMs(Date.now() - start))}`))
311+
stderr(green(`created ${bold(relativeId(o.file || o.dir))} (${prettyBytes(out.output.filter(o => o.code).reduce((n, o) => n + o.code.length, 0))}) in ${bold(prettyMs(Date.now() - start))}`))
312312
return bundle
313313
})
314314
}

src/loadConfigFile.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import tc from 'chalk'
21
import path from 'path'
3-
import rollup from 'rollup'
2+
import rollup, { InputOptions, RollupBuild, RollupOutput } from 'rollup'
43

54
import { relativeId } from './utils'
65
import batchWarnings from './utils/batchWarnings'
76
import { handleError, stderr } from './utils/logging'
87

98
import { getPluginCtor } from './plugins'
9+
import { bold } from './utils/colors'
1010

1111
const json = getPluginCtor('json')
1212

@@ -29,7 +29,7 @@ export function loadConfigFile (
2929
})
3030
.then((bundle: RollupBuild) => {
3131
if (!silent && warnings.count > 0) {
32-
stderr(tc.bold(`loaded ${relativeId(configFile)} with warnings`))
32+
stderr(bold(`loaded ${relativeId(configFile)} with warnings`))
3333
warnings.flush()
3434
}
3535

@@ -40,7 +40,7 @@ export function loadConfigFile (
4040
.then(({ output: [{ code }] }: RollupOutput) => {
4141
// temporarily override require
4242
const defaultLoader = require.extensions['.js']
43-
require.extensions['.js'] = (module: NodeModuleWithCompile, filename: string) => {
43+
require.extensions['.js'] = (module: any, filename: string) => {
4444
if (filename === configFile) {
4545
module._compile(code, filename)
4646
} else {

src/plugins/babel-custom.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { isEmpty, merge } from '@fdio/utils'
22
import { createBabelInputPluginFactory } from '@rollup/plugin-babel'
3-
import transformFastRest from './transform-fast-rest'
43

54
import { resolveModule } from '../utils'
65

6+
import transformFastRest from './transform-fast-rest'
7+
78
const isTruthy = v => !isEmpty(v)
89

910
const ESMODULES_TARGET = {
@@ -57,7 +58,7 @@ export default () => {
5758
return createBabelInputPluginFactory(babelCore => {
5859
return {
5960
// Passed the plugin options.
60-
options({ custom: customOptions, ...pluginOptions }) {
61+
options ({ custom: customOptions, ...pluginOptions }) {
6162
return {
6263
// Pull out any custom options that the plugin might have.
6364
customOptions,

src/plugins/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const plugins: Kv<PluginDefine> = {
3131
impl: () => loadModule('rollup-plugin-json5')
3232
},
3333
typescript: {
34-
impl: () => loadModule('rollup-plugin-typescript2')
34+
impl: () => loadModule('@rollup/plugin-typescript')
3535
}
3636
}
3737

@@ -66,7 +66,7 @@ export const loadPlugin = <T> (name: string): T | null => {
6666
throw new Error(`Cannot find plugin module '${name}`)
6767
}
6868

69-
// hack some plugin with named exports, eg: terser, minify
69+
// hack some plugin with named exports, { [pluginName]: () => {} }
7070
if (!isFunction(plugin) && isFunction(plugin[name])) {
7171
return plugin[name]
7272
}

src/plugins/options.ts

+28-27
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ import configLoader from '../utils/configLoader'
1818
// Extensions to use when resolving modules
1919
const EXTENSIONS = ['.ts', '.tsx', '.js', '.jsx', '.es6', '.es', '.mjs']
2020

21-
type RollupContext = {
21+
interface RollupContext {
2222
input: Kv;
2323
output: Kv;
2424
options: Kv;
2525
}
2626

27-
export type IPluginOptionParser <T = Kv> = (options: Partial<T>, ctx: RollupContext) => T;
27+
export type IPluginOptionParser <T = Kv> = (options: Partial<T>, ctx: RollupContext) => T
2828

2929
const findTsconfig = (
3030
entryFile: string,
@@ -101,35 +101,36 @@ const defaultPluginOpts: Kv<IPluginOptionParser> = {
101101

102102
typescript (o, { input, options, output: { format } }) {
103103
// resolve input tsconfig file
104-
const tsconfig = o.tsconfig || findTsconfig(input)
104+
// const tsconfig = o.tsconfig || findTsconfig(input)
105105

106106
// https://www.npmjs.com/package/rollup-plugin-typescript2#plugin-options
107107
return merge(
108108
{
109-
check: true,
110-
abortOnError: false,
111-
cacheRoot: `./node_modules/.cache/.rts2_cache_${format}`,
112-
// If true, declaration files will be emitted in the directory given in the
113-
// tsconfig. If false, the declaration files will be placed inside the destination
114-
// directory given in the Rollup configuration.
115-
useTsconfigDeclarationDir: false,
116-
tsconfigDefaults: {
117-
compilerOptions: {
118-
sourceMap: options.sourcemap,
119-
jsx: 'react',
120-
declaration: true,
121-
// [email protected] defaults to true, https://www.typescriptlang.org/tsconfig#useDefineForClassFields
122-
useDefineForClassFields: false
123-
}
124-
},
125-
// some ts options to been force overwrite
126-
tsconfigOverride: {
127-
compilerOptions: {
128-
target: 'esnext',
129-
newLine: 'lf'
130-
}
131-
}
132-
}, { ...o, tsconfig }
109+
// check: true,
110+
// abortOnError: false,
111+
// cacheRoot: `./node_modules/.cache/.rts2_cache_${format}`,
112+
// // If true, declaration files will be emitted in the directory given in the
113+
// // tsconfig. If false, the declaration files will be placed inside the destination
114+
// // directory given in the Rollup configuration.
115+
// useTsconfigDeclarationDir: false,
116+
// tsconfigDefaults: {
117+
// compilerOptions: {
118+
// sourceMap: options.sourcemap,
119+
// jsx: 'react',
120+
// declaration: true,
121+
// // [email protected] defaults to true, https://www.typescriptlang.org/tsconfig#useDefineForClassFields
122+
// useDefineForClassFields: false
123+
// }
124+
// },
125+
// // some ts options to been force overwrite
126+
// tsconfigOverride: {
127+
// compilerOptions: {
128+
// target: 'esnext',
129+
// newLine: 'lf'
130+
// }
131+
// }
132+
},
133+
o
133134
)
134135
},
135136

0 commit comments

Comments
 (0)