@mirta/rollup 0.2.6 → 0.2.8

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/dist/index.d.mts CHANGED
@@ -9,6 +9,11 @@ interface DotenvOptions {
9
9
  verbose: boolean;
10
10
  }
11
11
  interface RollupConfigOptions {
12
+ /** Настройки для монорепозитория. */
13
+ monorepo?: {
14
+ rootDir: string;
15
+ workspaces: string[];
16
+ };
12
17
  dotenv?: DotenvOptions;
13
18
  plugins?: Plugin[];
14
19
  }
package/dist/index.mjs CHANGED
@@ -4,6 +4,7 @@ import ts from 'rollup-plugin-typescript2';
4
4
  import dotenv from '@dotenv-run/rollup';
5
5
  import replace from '@rollup/plugin-replace';
6
6
  import { getBabelOutputPlugin } from '@rollup/plugin-babel';
7
+ import path$1 from 'node:path';
7
8
  import { deleteAsync } from 'del';
8
9
  import path from 'path';
9
10
  import MagicString from 'magic-string';
@@ -101,12 +102,37 @@ function wbRulesImports() {
101
102
 
102
103
  const env = process.env.NODE_ENV;
103
104
  const isProduction = env === 'production';
104
- const packagesPattern = /node_modules\/@?(.+)\/(.+)/;
105
- const modulesPattern = /(?:src\/)?wb-rules-modules\/(.*)/;
106
- const scriptsPattern = /(?:src\/)?(?:wb-rules\/)?(.*)/;
105
+ const packagesPattern = /node_modules[\\/]@?(.+)[\\/](.+)/;
106
+ const modulesPattern = /(?:src[\\/])?wb-rules-modules[\\/](.*)/;
107
+ const scriptsPattern = /(?:src[\\/])?(?:wb-rules[\\/])?(.*)/;
108
+ const cwd = process.cwd();
107
109
  const outputDir = {
108
110
  es5: 'dist/es5',
109
111
  };
112
+ function pathByGlobPattern(path, pattern) {
113
+ const pathParts = path.split('/');
114
+ const patternParts = pattern.split('/');
115
+ let i = 0; // Индекс текущего компонента пути.
116
+ for (let j = 0; j < patternParts.length && i < pathParts.length; j++) {
117
+ switch (patternParts[j]) {
118
+ case '*':
119
+ break;
120
+ case '**':
121
+ while (i < pathParts.length && !pathParts[i].startsWith(patternParts[j + 1])) {
122
+ i += 1; // Пропускаем все элементы пути до следующего элемента шаблона.
123
+ }
124
+ break;
125
+ default:
126
+ if (patternParts[j] === pathParts[i]) {
127
+ i += 1;
128
+ }
129
+ else {
130
+ return void 0; // Несоответствие фиксированного значения.
131
+ }
132
+ }
133
+ }
134
+ return pathParts.slice(i).join('/');
135
+ }
110
136
  function packageEntry(pkg, entry) {
111
137
  const key = entry ? `${pkg}/${entry}` : pkg;
112
138
  // if ((process.env.NODE_ENV !== 'production'))
@@ -154,7 +180,7 @@ function getEntry(path) {
154
180
  * @returns
155
181
  */
156
182
  function defineConfig(options = {}) {
157
- const { dotenv: dotenvOptions = {}, plugins = [] } = options;
183
+ const { dotenv: dotenvOptions = {}, plugins = [], monorepo, } = options;
158
184
  const defaultPlugins = [
159
185
  del({
160
186
  targets: 'dist/*',
@@ -199,11 +225,26 @@ function defineConfig(options = {}) {
199
225
  dir: outputDir.es5,
200
226
  preserveModules: true,
201
227
  entryFileNames(chunkInfo) {
202
- // console.log(process.cwd())
203
- // console.log(chunkInfo.name)
204
- // console.log(getEntry(chunkInfo.name))
205
- // console.log(chunkInfo)
206
- return getEntry(chunkInfo.name);
228
+ let chunkName = chunkInfo.name;
229
+ if (monorepo) {
230
+ const { rootDir, workspaces } = monorepo;
231
+ const absolutePath = path$1.resolve(rootDir, chunkInfo.name);
232
+ if (absolutePath.startsWith(cwd)) {
233
+ chunkName = path$1
234
+ .relative(cwd, absolutePath);
235
+ }
236
+ else {
237
+ for (const workspace of workspaces) {
238
+ const maybeChunkName = pathByGlobPattern(chunkName, workspace);
239
+ if (maybeChunkName) {
240
+ // Обманка для упрощённого встраивания в packages.
241
+ chunkName = 'node_modules/' + maybeChunkName;
242
+ break;
243
+ }
244
+ }
245
+ }
246
+ }
247
+ return getEntry(chunkName);
207
248
  },
208
249
  },
209
250
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mirta/rollup",
3
3
  "description": "Predefined Rollup configuration for wb-rules project builds.",
4
- "version": "0.2.6",
4
+ "version": "0.2.8",
5
5
  "license": "Unlicense",
6
6
  "keywords": [
7
7
  "mirta",
@@ -42,16 +42,13 @@
42
42
  "magic-string": "^0.30.19",
43
43
  "rollup-plugin-typescript2": "^0.36.0",
44
44
  "typescript": "^5.8.3",
45
- "@mirta/polyfills": "0.2.6"
45
+ "@mirta/polyfills": "0.2.8"
46
46
  },
47
47
  "devDependencies": {
48
48
  "rollup": "^4.50.0"
49
49
  },
50
- "publishConfig": {
51
- "access": "public"
52
- },
53
50
  "scripts": {
54
- "clean": "rimraf dist build",
55
- "build": "pnpm clean && rollup -c ../../rollup.config.mjs"
51
+ "clean": "rimraf dist",
52
+ "build:mono": "pnpm clean && rollup -c ../../rollup.config.mjs"
56
53
  }
57
54
  }