/
npmPlugins.js
107 lines (101 loc) · 3.47 KB
/
npmPlugins.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/**
* Rollup plugin hooks docs: https://rollupjs.org/guide/en/#build-hooks and
* https://rollupjs.org/guide/en/#output-generation-hooks
*
* Cleanup plugin docs: https://github.com/aMarCruz/rollup-plugin-cleanup
* Replace plugin docs: https://github.com/rollup/plugins/tree/master/packages/replace
* Sucrase plugin docs: https://github.com/rollup/plugins/tree/master/packages/sucrase
*/
import cleanup from 'rollup-plugin-cleanup';
import replace from '@rollup/plugin-replace';
import sucrase from '@rollup/plugin-sucrase';
/**
* Create a plugin to transpile TS syntax using `sucrase`.
*
* @returns An instance of the `@rollup/plugin-sucrase` plugin
*/
export function makeSucrasePlugin() {
return sucrase({
transforms: ['typescript', 'jsx'],
});
}
/**
* Create a plugin which can be used to pause the build process at the given hook.
*
* Hooks can be found at https://rollupjs.org/guide/en/#build-hooks and
* https://rollupjs.org/guide/en/#output-generation-hooks.
*
* @param hookName The name of the hook at which to pause.
* @returns A plugin which inserts a debugger statement in the phase represented by the given hook
*
* For convenience, here are pre-built debuggers for every hook:
*
* makeDebuggerPlugin('buildStart'),
* makeDebuggerPlugin('options'),
* makeDebuggerPlugin('resolveId'),
* makeDebuggerPlugin('resolveDynamicImport'),
* makeDebuggerPlugin('load'),
* makeDebuggerPlugin('transform'),
* makeDebuggerPlugin('shouldTransformCachedModule'),
* makeDebuggerPlugin('moduleParsed'),
* makeDebuggerPlugin('buildEnd'),
* makeDebuggerPlugin('watchChange'),
* makeDebuggerPlugin('closeWatcher'),
* makeDebuggerPlugin('outputOptions'),
* makeDebuggerPlugin('renderStart'),
* makeDebuggerPlugin('banner'),
* makeDebuggerPlugin('footer'),
* makeDebuggerPlugin('intro'),
* makeDebuggerPlugin('outro'),
* makeDebuggerPlugin('augmentChunkHash'),
* makeDebuggerPlugin('renderDynamicImport'),
* makeDebuggerPlugin('resolveFileUrl'),
* makeDebuggerPlugin('resolveImportMeta'),
* makeDebuggerPlugin('renderChunk'),
* makeDebuggerPlugin('renderError'),
* makeDebuggerPlugin('generateBundle'),
* makeDebuggerPlugin('writeBundle'),
* makeDebuggerPlugin('closeBundle'),
*/
export function makeDebuggerPlugin(hookName) {
return {
name: 'debugger-plugin',
[hookName]: (..._args) => {
// eslint-disable-next-line no-debugger
debugger;
return null;
},
};
}
/**
* Create a plugin to clean up output files by:
* - Converting line endings unix line endings
* - Removing consecutive empty lines
*
* @returns A `rollup-plugin-cleanup` instance.
*/
export function makeCleanupPlugin() {
return cleanup({
// line endings are unix-ized by default
comments: 'all', // comments to keep
compactComments: 'false', // don't remove blank lines in multi-line comments
maxEmptyLines: 1,
extensions: ['js', 'jsx', 'ts', 'tsx'],
});
}
/**
* Creates a plugin to replace all instances of "__DEBUG_BUILD__" with a safe statement that
* a) evaluates to `true`
* b) can easily be modified by our users' bundlers to evaluate to false, facilitating the treeshaking of logger code.
*
* @returns A `@rollup/plugin-replace` instance.
*/
export function makeDebugBuildStatementReplacePlugin() {
return replace({
preventAssignment: false,
values: {
__DEBUG_BUILD__: "(typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__)",
},
});
}
export { makeExtractPolyfillsPlugin } from './extractPolyfillsPlugin.js';