@pgpmjs/slice 0.14.2 → 0.14.4
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/esm/slice.js +17 -2
- package/package.json +5 -5
- package/slice.js +16 -1
package/esm/slice.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { parsePlanFile } from '@pgpmjs/ast/files/plan/parser';
|
|
2
2
|
import { generateChangeLineContent, generateTagLineContent } from '@pgpmjs/ast/files/plan/writer';
|
|
3
|
-
import {
|
|
3
|
+
import { Minimatch } from 'minimatch';
|
|
4
4
|
import { buildAstEdges, expandClosures } from './closure';
|
|
5
5
|
/**
|
|
6
6
|
* Build a dependency graph from a parsed plan file
|
|
@@ -86,6 +86,21 @@ export function extractPackageFromPath(changeName, depth = 1, prefixToStrip = 's
|
|
|
86
86
|
}
|
|
87
87
|
return 'core';
|
|
88
88
|
}
|
|
89
|
+
/**
|
|
90
|
+
* Compiling a glob costs far more than matching one, and assigning a plan
|
|
91
|
+
* evaluates every (change x pattern) pair — hundreds of thousands of pairs on
|
|
92
|
+
* a large plan over the same handful of patterns — so each pattern is
|
|
93
|
+
* compiled once and reused. `Minimatch` instances are stateless.
|
|
94
|
+
*/
|
|
95
|
+
const patternMatchers = new Map();
|
|
96
|
+
function patternMatcher(pattern) {
|
|
97
|
+
let matcher = patternMatchers.get(pattern);
|
|
98
|
+
if (!matcher) {
|
|
99
|
+
matcher = new Minimatch(pattern, { dot: true });
|
|
100
|
+
patternMatchers.set(pattern, matcher);
|
|
101
|
+
}
|
|
102
|
+
return matcher;
|
|
103
|
+
}
|
|
89
104
|
/**
|
|
90
105
|
* Find the matching package for a change using pattern-based strategy.
|
|
91
106
|
* Returns the first matching slice's package name, or undefined if no match.
|
|
@@ -93,7 +108,7 @@ export function extractPackageFromPath(changeName, depth = 1, prefixToStrip = 's
|
|
|
93
108
|
export function findMatchingPattern(changeName, strategy) {
|
|
94
109
|
for (const slice of strategy.slices) {
|
|
95
110
|
for (const pattern of slice.patterns) {
|
|
96
|
-
if (
|
|
111
|
+
if (patternMatcher(pattern).match(changeName)) {
|
|
97
112
|
return slice.packageName;
|
|
98
113
|
}
|
|
99
114
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pgpmjs/slice",
|
|
3
|
-
"version": "0.14.
|
|
3
|
+
"version": "0.14.4",
|
|
4
4
|
"author": "Constructive <developers@constructive.io>",
|
|
5
5
|
"description": "PGPM plan slicing — split a monolithic pgpm plan into packages with pattern strategies and opt-in AST-based dependency closure",
|
|
6
6
|
"main": "index.js",
|
|
@@ -42,10 +42,10 @@
|
|
|
42
42
|
"makage": "^0.3.0"
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@pgpmjs/ast": "^0.11.
|
|
46
|
-
"@pgpmjs/transform": "^0.23.
|
|
47
|
-
"minimatch": "^10.2.
|
|
45
|
+
"@pgpmjs/ast": "^0.11.3",
|
|
46
|
+
"@pgpmjs/transform": "^0.23.2",
|
|
47
|
+
"minimatch": "^10.2.6",
|
|
48
48
|
"plpgsql-parser": "^18.5.3"
|
|
49
49
|
},
|
|
50
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "0d9f0718a8c768cc8b7659525953dc762833bd6b"
|
|
51
51
|
}
|
package/slice.js
CHANGED
|
@@ -102,6 +102,21 @@ function extractPackageFromPath(changeName, depth = 1, prefixToStrip = 'schemas'
|
|
|
102
102
|
}
|
|
103
103
|
return 'core';
|
|
104
104
|
}
|
|
105
|
+
/**
|
|
106
|
+
* Compiling a glob costs far more than matching one, and assigning a plan
|
|
107
|
+
* evaluates every (change x pattern) pair — hundreds of thousands of pairs on
|
|
108
|
+
* a large plan over the same handful of patterns — so each pattern is
|
|
109
|
+
* compiled once and reused. `Minimatch` instances are stateless.
|
|
110
|
+
*/
|
|
111
|
+
const patternMatchers = new Map();
|
|
112
|
+
function patternMatcher(pattern) {
|
|
113
|
+
let matcher = patternMatchers.get(pattern);
|
|
114
|
+
if (!matcher) {
|
|
115
|
+
matcher = new minimatch_1.Minimatch(pattern, { dot: true });
|
|
116
|
+
patternMatchers.set(pattern, matcher);
|
|
117
|
+
}
|
|
118
|
+
return matcher;
|
|
119
|
+
}
|
|
105
120
|
/**
|
|
106
121
|
* Find the matching package for a change using pattern-based strategy.
|
|
107
122
|
* Returns the first matching slice's package name, or undefined if no match.
|
|
@@ -109,7 +124,7 @@ function extractPackageFromPath(changeName, depth = 1, prefixToStrip = 'schemas'
|
|
|
109
124
|
function findMatchingPattern(changeName, strategy) {
|
|
110
125
|
for (const slice of strategy.slices) {
|
|
111
126
|
for (const pattern of slice.patterns) {
|
|
112
|
-
if ((
|
|
127
|
+
if (patternMatcher(pattern).match(changeName)) {
|
|
113
128
|
return slice.packageName;
|
|
114
129
|
}
|
|
115
130
|
}
|