@quilted/rollup 0.1.8 → 0.1.10

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 CHANGED
@@ -1,5 +1,21 @@
1
1
  # @quilted/rollup
2
2
 
3
+ ## 0.1.10
4
+
5
+ ### Patch Changes
6
+
7
+ - [`488b2c89`](https://github.com/lemonmade/quilt/commit/488b2c89b467b97feaf1e6f189bbf8c1aeea80f3) Thanks [@lemonmade](https://github.com/lemonmade)! - Delete build files on build
8
+
9
+ - [`0dafd7d0`](https://github.com/lemonmade/quilt/commit/0dafd7d02d9a361e06b2968f3dda48a30552a1f1) Thanks [@lemonmade](https://github.com/lemonmade)! - Add support for browserlist configuration
10
+
11
+ ## 0.1.9
12
+
13
+ ### Patch Changes
14
+
15
+ - [`afadefe6`](https://github.com/lemonmade/quilt/commit/afadefe6d6fc6b62c17bbc318f9c13c50ef50b7b) Thanks [@lemonmade](https://github.com/lemonmade)! - Add automatic detection of entrypoints
16
+
17
+ - [`36751497`](https://github.com/lemonmade/quilt/commit/36751497d36fd9bea227c2baf55a302d54468863) Thanks [@lemonmade](https://github.com/lemonmade)! - Add tsconfig aliases plugin
18
+
3
19
  ## 0.1.8
4
20
 
5
21
  ### Patch Changes
package/build/cjs/app.cjs CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  var path = require('node:path');
4
4
  var fs = require('node:fs/promises');
5
+ var glob = require('glob');
5
6
  var constants = require('./constants.cjs');
6
7
  var strings = require('./shared/strings.cjs');
7
8
  var rollup = require('./shared/rollup.cjs');
@@ -29,21 +30,37 @@ var fs__namespace = /*#__PURE__*/_interopNamespaceDefault(fs);
29
30
 
30
31
  async function quiltAppBrowser({
31
32
  app,
32
- entry = constants.MAGIC_MODULE_ENTRY,
33
+ entry,
33
34
  env,
34
35
  assets,
35
36
  module,
36
37
  graphql = true
37
38
  } = {}) {
39
+ const root = process.cwd();
38
40
  const mode = (typeof env === 'object' ? env?.mode : undefined) ?? 'production';
39
41
  const minify = assets?.minify ?? mode === 'production';
40
42
  const baseURL = assets?.baseURL ?? '/assets/';
43
+ const assetTargets = assets?.targets ?? {};
44
+ const targets = Array.isArray(assetTargets) ? {
45
+ browsers: assetTargets
46
+ } : assetTargets;
47
+ const targetBrowsers = targets.browsers ?? (await (async () => {
48
+ const {
49
+ default: browserslist
50
+ } = await import('browserslist');
51
+ const config = browserslist.findConfig(root);
52
+ if (config == null) return ['defaults'];
53
+ const targetName = targets.name ?? 'defaults';
54
+ return config[targetName] ?? ['defaults'];
55
+ })());
41
56
  const [{
42
57
  visualizer
43
58
  }, {
44
59
  assetManifest
45
60
  }, {
46
61
  sourceCode
62
+ }, {
63
+ createTSConfigAliasPlugin
47
64
  }, {
48
65
  css
49
66
  }, {
@@ -51,18 +68,25 @@ async function quiltAppBrowser({
51
68
  staticAssets
52
69
  }, {
53
70
  systemJS
54
- }, nodePlugins] = await Promise.all([import('rollup-plugin-visualizer'), import('@quilted/assets/rollup'), Promise.resolve().then(function () { return require('./features/source-code.cjs'); }), Promise.resolve().then(function () { return require('./features/css.cjs'); }), Promise.resolve().then(function () { return require('./features/assets.cjs'); }), Promise.resolve().then(function () { return require('./features/system-js.cjs'); }), rollup.getNodePlugins()]);
71
+ }, nodePlugins] = await Promise.all([import('rollup-plugin-visualizer'), import('@quilted/assets/rollup'), Promise.resolve().then(function () { return require('./features/source-code.cjs'); }), Promise.resolve().then(function () { return require('./features/typescript.cjs'); }), Promise.resolve().then(function () { return require('./features/css.cjs'); }), Promise.resolve().then(function () { return require('./features/assets.cjs'); }), Promise.resolve().then(function () { return require('./features/system-js.cjs'); }), rollup.getNodePlugins()]);
55
72
  const plugins = [...nodePlugins, systemJS({
56
73
  minify
57
74
  }), sourceCode({
58
- mode
75
+ mode,
76
+ targets: targetBrowsers
59
77
  }), css({
60
78
  minify,
61
79
  emit: true
62
80
  }), rawAssets(), staticAssets({
63
81
  baseURL,
64
82
  emit: true
83
+ }), rollup.removeBuildFiles(['build/assets', 'build/manifests', 'build/reports'], {
84
+ root
65
85
  })];
86
+ const tsconfigAliases = await createTSConfigAliasPlugin();
87
+ if (tsconfigAliases) {
88
+ plugins.push(tsconfigAliases);
89
+ }
66
90
  if (env) {
67
91
  const {
68
92
  magicModuleEnv,
@@ -84,9 +108,14 @@ async function quiltAppBrowser({
84
108
  }));
85
109
  }
86
110
  }
87
- if (app) {
111
+ const appEntry = app ?? (await glob.glob('{App,app,input}.{ts,tsx,mjs,js,jsx}', {
112
+ cwd: root,
113
+ nodir: true,
114
+ absolute: true
115
+ }).then(files => files[0]));
116
+ if (appEntry) {
88
117
  plugins.push(magicModuleAppComponent({
89
- entry: app
118
+ entry: appEntry
90
119
  }));
91
120
  }
92
121
  plugins.push(magicModuleAppBrowserEntry(module));
@@ -104,19 +133,31 @@ async function quiltAppBrowser({
104
133
  } = await import('rollup-plugin-esbuild');
105
134
  plugins.push(minify());
106
135
  }
136
+ const cacheKey = targets.name ? {
137
+ browserTarget: targets.name
138
+ } : undefined;
139
+ const id = targets.name ? targets.name : undefined;
107
140
  plugins.push(
108
141
  // @ts-expect-error The plugin still depends on Rollup 3
109
142
  assetManifest({
143
+ id,
144
+ cacheKey,
110
145
  baseUrl: baseURL,
111
- path: path__namespace.resolve(`build/manifests/assets.json`)
146
+ path: path__namespace.resolve(`build/manifests/assets.json`),
147
+ priority: assets?.priority
112
148
  }), visualizer({
113
149
  template: 'treemap',
114
150
  open: false,
115
151
  brotliSize: true,
116
152
  filename: path__namespace.resolve(`build/reports/bundle-visualizer.html`)
117
153
  }));
154
+ const finalEntry = entry ?? (await glob.glob('{browser,client}.{ts,tsx,mjs,js,jsx}', {
155
+ cwd: root,
156
+ nodir: true,
157
+ absolute: true
158
+ }).then(files => files[0])) ?? constants.MAGIC_MODULE_ENTRY;
118
159
  return {
119
- input: entry,
160
+ input: finalEntry,
120
161
  plugins,
121
162
  onwarn(warning, defaultWarn) {
122
163
  // Removes annoying warnings for React-focused libraries that
@@ -140,15 +181,18 @@ async function quiltAppBrowser({
140
181
  async function quiltAppServer({
141
182
  app,
142
183
  env,
184
+ entry,
143
185
  graphql = true,
144
- entry = constants.MAGIC_MODULE_ENTRY,
145
186
  minify = false
146
187
  } = {}) {
188
+ const root = process.cwd();
147
189
  const mode = (typeof env === 'object' ? env?.mode : undefined) ?? 'production';
148
190
  const [{
149
191
  visualizer
150
192
  }, {
151
193
  sourceCode
194
+ }, {
195
+ createTSConfigAliasPlugin
152
196
  }, {
153
197
  css
154
198
  }, {
@@ -156,15 +200,22 @@ async function quiltAppServer({
156
200
  staticAssets
157
201
  }, {
158
202
  magicModuleRequestRouterEntry
159
- }, nodePlugins] = await Promise.all([import('rollup-plugin-visualizer'), Promise.resolve().then(function () { return require('./features/source-code.cjs'); }), Promise.resolve().then(function () { return require('./features/css.cjs'); }), Promise.resolve().then(function () { return require('./features/assets.cjs'); }), Promise.resolve().then(function () { return require('./features/request-router.cjs'); }), rollup.getNodePlugins()]);
203
+ }, nodePlugins] = await Promise.all([import('rollup-plugin-visualizer'), Promise.resolve().then(function () { return require('./features/source-code.cjs'); }), Promise.resolve().then(function () { return require('./features/typescript.cjs'); }), Promise.resolve().then(function () { return require('./features/css.cjs'); }), Promise.resolve().then(function () { return require('./features/assets.cjs'); }), Promise.resolve().then(function () { return require('./features/request-router.cjs'); }), rollup.getNodePlugins()]);
160
204
  const plugins = [...nodePlugins, sourceCode({
161
- mode
205
+ mode,
206
+ targets: ['current node']
162
207
  }), css({
163
208
  emit: false,
164
209
  minify
165
210
  }), rawAssets(), staticAssets({
166
211
  emit: false
212
+ }), rollup.removeBuildFiles(['build/server'], {
213
+ root
167
214
  })];
215
+ const tsconfigAliases = await createTSConfigAliasPlugin();
216
+ if (tsconfigAliases) {
217
+ plugins.push(tsconfigAliases);
218
+ }
168
219
  if (env) {
169
220
  const {
170
221
  magicModuleEnv,
@@ -186,9 +237,14 @@ async function quiltAppServer({
186
237
  }));
187
238
  }
188
239
  }
189
- if (app) {
240
+ const appEntry = app ?? (await glob.glob('{App,app,input}.{ts,tsx,mjs,js,jsx}', {
241
+ cwd: root,
242
+ nodir: true,
243
+ absolute: true
244
+ }).then(files => files[0]));
245
+ if (appEntry) {
190
246
  plugins.push(magicModuleAppComponent({
191
- entry: app
247
+ entry: appEntry
192
248
  }));
193
249
  }
194
250
  plugins.push(magicModuleRequestRouterEntry());
@@ -216,8 +272,13 @@ async function quiltAppServer({
216
272
  brotliSize: true,
217
273
  filename: path__namespace.resolve(`build/reports/bundle-visualizer.html`)
218
274
  }));
275
+ const finalEntry = entry ?? (await glob.glob('{server,service,backend}.{ts,tsx,mjs,js,jsx}', {
276
+ cwd: root,
277
+ nodir: true,
278
+ absolute: true
279
+ }).then(files => files[0])) ?? constants.MAGIC_MODULE_ENTRY;
219
280
  return {
220
- input: entry,
281
+ input: finalEntry,
221
282
  plugins,
222
283
  onwarn(warning, defaultWarn) {
223
284
  // Removes annoying warnings for React-focused libraries that
@@ -0,0 +1,56 @@
1
+ 'use strict';
2
+
3
+ var path = require('node:path');
4
+ var fs = require('node:fs');
5
+
6
+ function _interopNamespaceDefault(e) {
7
+ var n = Object.create(null);
8
+ if (e) {
9
+ Object.keys(e).forEach(function (k) {
10
+ if (k !== 'default') {
11
+ var d = Object.getOwnPropertyDescriptor(e, k);
12
+ Object.defineProperty(n, k, d.get ? d : {
13
+ enumerable: true,
14
+ get: function () { return e[k]; }
15
+ });
16
+ }
17
+ });
18
+ }
19
+ n["default"] = e;
20
+ return Object.freeze(n);
21
+ }
22
+
23
+ var path__namespace = /*#__PURE__*/_interopNamespaceDefault(path);
24
+ var fs__namespace = /*#__PURE__*/_interopNamespaceDefault(fs);
25
+
26
+ async function createTSConfigAliasPlugin({
27
+ root = process.cwd()
28
+ } = {}) {
29
+ const [{
30
+ default: alias
31
+ }, tsconfig] = await Promise.all([import('@rollup/plugin-alias'), getTSConfig(root)]);
32
+ const tsconfigPaths = tsconfig?.compilerOptions?.paths;
33
+ if (tsconfigPaths == null) return undefined;
34
+ return alias({
35
+ entries: Object.entries(tsconfigPaths).map(([name, aliases]) => {
36
+ return {
37
+ find: name.includes('*') ? new RegExp(`^${name.replace(/\*/, '(.*)')}$`) : name,
38
+ replacement: aliases[0].replace('*', '$1')
39
+ };
40
+ })
41
+ });
42
+ }
43
+ async function getTSConfig(root) {
44
+ const tsconfigPath = path__namespace.join(root, 'tsconfig.json');
45
+ if (!fs__namespace.existsSync(tsconfigPath)) {
46
+ return undefined;
47
+ }
48
+ try {
49
+ const tsconfig = JSON.parse(await fs__namespace.promises.readFile(tsconfigPath, 'utf8'));
50
+ return tsconfig;
51
+ } catch {
52
+ // intentional noop
53
+ }
54
+ }
55
+
56
+ exports.createTSConfigAliasPlugin = createTSConfigAliasPlugin;
@@ -1,7 +1,28 @@
1
1
  'use strict';
2
2
 
3
+ var fs = require('node:fs/promises');
4
+ var glob = require('glob');
3
5
  var replace = require('@rollup/plugin-replace');
4
6
 
7
+ function _interopNamespaceDefault(e) {
8
+ var n = Object.create(null);
9
+ if (e) {
10
+ Object.keys(e).forEach(function (k) {
11
+ if (k !== 'default') {
12
+ var d = Object.getOwnPropertyDescriptor(e, k);
13
+ Object.defineProperty(n, k, d.get ? d : {
14
+ enumerable: true,
15
+ get: function () { return e[k]; }
16
+ });
17
+ }
18
+ });
19
+ }
20
+ n["default"] = e;
21
+ return Object.freeze(n);
22
+ }
23
+
24
+ var fs__namespace = /*#__PURE__*/_interopNamespaceDefault(fs);
25
+
5
26
  function smartReplace(values, options) {
6
27
  return replace({
7
28
  // @see https://github.com/vitejs/vite/blob/2b1ffe86328f9d06ef9528ee117b61889893ddcc/packages/vite/src/node/plugins/define.ts#L108-L119
@@ -11,6 +32,23 @@ function smartReplace(values, options) {
11
32
  values
12
33
  });
13
34
  }
35
+ function removeBuildFiles(patterns, {
36
+ root = process.cwd()
37
+ } = {}) {
38
+ return {
39
+ name: '@quilt/remove-build-files',
40
+ async buildStart() {
41
+ const matches = await glob.glob(patterns, {
42
+ cwd: root,
43
+ absolute: true
44
+ });
45
+ await Promise.all(matches.map(file => fs__namespace.rm(file, {
46
+ recursive: true,
47
+ force: true
48
+ })));
49
+ }
50
+ };
51
+ }
14
52
  async function getNodePlugins() {
15
53
  const [{
16
54
  default: commonjs
@@ -30,4 +68,5 @@ async function getNodePlugins() {
30
68
  }
31
69
 
32
70
  exports.getNodePlugins = getNodePlugins;
71
+ exports.removeBuildFiles = removeBuildFiles;
33
72
  exports.smartReplace = smartReplace;
package/build/esm/app.mjs CHANGED
@@ -1,27 +1,44 @@
1
1
  import * as path from 'node:path';
2
2
  import * as fs from 'node:fs/promises';
3
+ import { glob } from 'glob';
3
4
  import { MAGIC_MODULE_ENTRY, MAGIC_MODULE_APP_COMPONENT, MAGIC_MODULE_REQUEST_ROUTER, MAGIC_MODULE_BROWSER_ASSETS } from './constants.mjs';
4
5
  import { multiline } from './shared/strings.mjs';
5
- import { getNodePlugins } from './shared/rollup.mjs';
6
+ import { getNodePlugins, removeBuildFiles } from './shared/rollup.mjs';
6
7
  import { createMagicModulePlugin } from './shared/magic-module.mjs';
7
8
 
8
9
  async function quiltAppBrowser({
9
10
  app,
10
- entry = MAGIC_MODULE_ENTRY,
11
+ entry,
11
12
  env,
12
13
  assets,
13
14
  module,
14
15
  graphql = true
15
16
  } = {}) {
17
+ const root = process.cwd();
16
18
  const mode = (typeof env === 'object' ? env?.mode : undefined) ?? 'production';
17
19
  const minify = assets?.minify ?? mode === 'production';
18
20
  const baseURL = assets?.baseURL ?? '/assets/';
21
+ const assetTargets = assets?.targets ?? {};
22
+ const targets = Array.isArray(assetTargets) ? {
23
+ browsers: assetTargets
24
+ } : assetTargets;
25
+ const targetBrowsers = targets.browsers ?? (await (async () => {
26
+ const {
27
+ default: browserslist
28
+ } = await import('browserslist');
29
+ const config = browserslist.findConfig(root);
30
+ if (config == null) return ['defaults'];
31
+ const targetName = targets.name ?? 'defaults';
32
+ return config[targetName] ?? ['defaults'];
33
+ })());
19
34
  const [{
20
35
  visualizer
21
36
  }, {
22
37
  assetManifest
23
38
  }, {
24
39
  sourceCode
40
+ }, {
41
+ createTSConfigAliasPlugin
25
42
  }, {
26
43
  css
27
44
  }, {
@@ -29,18 +46,25 @@ async function quiltAppBrowser({
29
46
  staticAssets
30
47
  }, {
31
48
  systemJS
32
- }, nodePlugins] = await Promise.all([import('rollup-plugin-visualizer'), import('@quilted/assets/rollup'), import('./features/source-code.mjs'), import('./features/css.mjs'), import('./features/assets.mjs'), import('./features/system-js.mjs'), getNodePlugins()]);
49
+ }, nodePlugins] = await Promise.all([import('rollup-plugin-visualizer'), import('@quilted/assets/rollup'), import('./features/source-code.mjs'), import('./features/typescript.mjs'), import('./features/css.mjs'), import('./features/assets.mjs'), import('./features/system-js.mjs'), getNodePlugins()]);
33
50
  const plugins = [...nodePlugins, systemJS({
34
51
  minify
35
52
  }), sourceCode({
36
- mode
53
+ mode,
54
+ targets: targetBrowsers
37
55
  }), css({
38
56
  minify,
39
57
  emit: true
40
58
  }), rawAssets(), staticAssets({
41
59
  baseURL,
42
60
  emit: true
61
+ }), removeBuildFiles(['build/assets', 'build/manifests', 'build/reports'], {
62
+ root
43
63
  })];
64
+ const tsconfigAliases = await createTSConfigAliasPlugin();
65
+ if (tsconfigAliases) {
66
+ plugins.push(tsconfigAliases);
67
+ }
44
68
  if (env) {
45
69
  const {
46
70
  magicModuleEnv,
@@ -62,9 +86,14 @@ async function quiltAppBrowser({
62
86
  }));
63
87
  }
64
88
  }
65
- if (app) {
89
+ const appEntry = app ?? (await glob('{App,app,input}.{ts,tsx,mjs,js,jsx}', {
90
+ cwd: root,
91
+ nodir: true,
92
+ absolute: true
93
+ }).then(files => files[0]));
94
+ if (appEntry) {
66
95
  plugins.push(magicModuleAppComponent({
67
- entry: app
96
+ entry: appEntry
68
97
  }));
69
98
  }
70
99
  plugins.push(magicModuleAppBrowserEntry(module));
@@ -82,19 +111,31 @@ async function quiltAppBrowser({
82
111
  } = await import('rollup-plugin-esbuild');
83
112
  plugins.push(minify());
84
113
  }
114
+ const cacheKey = targets.name ? {
115
+ browserTarget: targets.name
116
+ } : undefined;
117
+ const id = targets.name ? targets.name : undefined;
85
118
  plugins.push(
86
119
  // @ts-expect-error The plugin still depends on Rollup 3
87
120
  assetManifest({
121
+ id,
122
+ cacheKey,
88
123
  baseUrl: baseURL,
89
- path: path.resolve(`build/manifests/assets.json`)
124
+ path: path.resolve(`build/manifests/assets.json`),
125
+ priority: assets?.priority
90
126
  }), visualizer({
91
127
  template: 'treemap',
92
128
  open: false,
93
129
  brotliSize: true,
94
130
  filename: path.resolve(`build/reports/bundle-visualizer.html`)
95
131
  }));
132
+ const finalEntry = entry ?? (await glob('{browser,client}.{ts,tsx,mjs,js,jsx}', {
133
+ cwd: root,
134
+ nodir: true,
135
+ absolute: true
136
+ }).then(files => files[0])) ?? MAGIC_MODULE_ENTRY;
96
137
  return {
97
- input: entry,
138
+ input: finalEntry,
98
139
  plugins,
99
140
  onwarn(warning, defaultWarn) {
100
141
  // Removes annoying warnings for React-focused libraries that
@@ -118,15 +159,18 @@ async function quiltAppBrowser({
118
159
  async function quiltAppServer({
119
160
  app,
120
161
  env,
162
+ entry,
121
163
  graphql = true,
122
- entry = MAGIC_MODULE_ENTRY,
123
164
  minify = false
124
165
  } = {}) {
166
+ const root = process.cwd();
125
167
  const mode = (typeof env === 'object' ? env?.mode : undefined) ?? 'production';
126
168
  const [{
127
169
  visualizer
128
170
  }, {
129
171
  sourceCode
172
+ }, {
173
+ createTSConfigAliasPlugin
130
174
  }, {
131
175
  css
132
176
  }, {
@@ -134,15 +178,22 @@ async function quiltAppServer({
134
178
  staticAssets
135
179
  }, {
136
180
  magicModuleRequestRouterEntry
137
- }, nodePlugins] = await Promise.all([import('rollup-plugin-visualizer'), import('./features/source-code.mjs'), import('./features/css.mjs'), import('./features/assets.mjs'), import('./features/request-router.mjs'), getNodePlugins()]);
181
+ }, nodePlugins] = await Promise.all([import('rollup-plugin-visualizer'), import('./features/source-code.mjs'), import('./features/typescript.mjs'), import('./features/css.mjs'), import('./features/assets.mjs'), import('./features/request-router.mjs'), getNodePlugins()]);
138
182
  const plugins = [...nodePlugins, sourceCode({
139
- mode
183
+ mode,
184
+ targets: ['current node']
140
185
  }), css({
141
186
  emit: false,
142
187
  minify
143
188
  }), rawAssets(), staticAssets({
144
189
  emit: false
190
+ }), removeBuildFiles(['build/server'], {
191
+ root
145
192
  })];
193
+ const tsconfigAliases = await createTSConfigAliasPlugin();
194
+ if (tsconfigAliases) {
195
+ plugins.push(tsconfigAliases);
196
+ }
146
197
  if (env) {
147
198
  const {
148
199
  magicModuleEnv,
@@ -164,9 +215,14 @@ async function quiltAppServer({
164
215
  }));
165
216
  }
166
217
  }
167
- if (app) {
218
+ const appEntry = app ?? (await glob('{App,app,input}.{ts,tsx,mjs,js,jsx}', {
219
+ cwd: root,
220
+ nodir: true,
221
+ absolute: true
222
+ }).then(files => files[0]));
223
+ if (appEntry) {
168
224
  plugins.push(magicModuleAppComponent({
169
- entry: app
225
+ entry: appEntry
170
226
  }));
171
227
  }
172
228
  plugins.push(magicModuleRequestRouterEntry());
@@ -194,8 +250,13 @@ async function quiltAppServer({
194
250
  brotliSize: true,
195
251
  filename: path.resolve(`build/reports/bundle-visualizer.html`)
196
252
  }));
253
+ const finalEntry = entry ?? (await glob('{server,service,backend}.{ts,tsx,mjs,js,jsx}', {
254
+ cwd: root,
255
+ nodir: true,
256
+ absolute: true
257
+ }).then(files => files[0])) ?? MAGIC_MODULE_ENTRY;
197
258
  return {
198
- input: entry,
259
+ input: finalEntry,
199
260
  plugins,
200
261
  onwarn(warning, defaultWarn) {
201
262
  // Removes annoying warnings for React-focused libraries that
@@ -0,0 +1,34 @@
1
+ import * as path from 'node:path';
2
+ import * as fs from 'node:fs';
3
+
4
+ async function createTSConfigAliasPlugin({
5
+ root = process.cwd()
6
+ } = {}) {
7
+ const [{
8
+ default: alias
9
+ }, tsconfig] = await Promise.all([import('@rollup/plugin-alias'), getTSConfig(root)]);
10
+ const tsconfigPaths = tsconfig?.compilerOptions?.paths;
11
+ if (tsconfigPaths == null) return undefined;
12
+ return alias({
13
+ entries: Object.entries(tsconfigPaths).map(([name, aliases]) => {
14
+ return {
15
+ find: name.includes('*') ? new RegExp(`^${name.replace(/\*/, '(.*)')}$`) : name,
16
+ replacement: aliases[0].replace('*', '$1')
17
+ };
18
+ })
19
+ });
20
+ }
21
+ async function getTSConfig(root) {
22
+ const tsconfigPath = path.join(root, 'tsconfig.json');
23
+ if (!fs.existsSync(tsconfigPath)) {
24
+ return undefined;
25
+ }
26
+ try {
27
+ const tsconfig = JSON.parse(await fs.promises.readFile(tsconfigPath, 'utf8'));
28
+ return tsconfig;
29
+ } catch {
30
+ // intentional noop
31
+ }
32
+ }
33
+
34
+ export { createTSConfigAliasPlugin };
@@ -1,3 +1,5 @@
1
+ import * as fs from 'node:fs/promises';
2
+ import { glob } from 'glob';
1
3
  import replace from '@rollup/plugin-replace';
2
4
 
3
5
  function smartReplace(values, options) {
@@ -9,6 +11,23 @@ function smartReplace(values, options) {
9
11
  values
10
12
  });
11
13
  }
14
+ function removeBuildFiles(patterns, {
15
+ root = process.cwd()
16
+ } = {}) {
17
+ return {
18
+ name: '@quilt/remove-build-files',
19
+ async buildStart() {
20
+ const matches = await glob(patterns, {
21
+ cwd: root,
22
+ absolute: true
23
+ });
24
+ await Promise.all(matches.map(file => fs.rm(file, {
25
+ recursive: true,
26
+ force: true
27
+ })));
28
+ }
29
+ };
30
+ }
12
31
  async function getNodePlugins() {
13
32
  const [{
14
33
  default: commonjs
@@ -27,4 +46,4 @@ async function getNodePlugins() {
27
46
  }), commonjs(), json()];
28
47
  }
29
48
 
30
- export { getNodePlugins, smartReplace };
49
+ export { getNodePlugins, removeBuildFiles, smartReplace };