@lowdefy/build 0.0.0-experimental-20251203183323 → 0.0.0-experimental-20251203191458

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.
@@ -12,14 +12,8 @@
12
12
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
13
  See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
- */ import { BuildParser } from '@lowdefy/operators';
16
- import operators from '@lowdefy/operators-js/operators/build';
17
- async function evaluateBuildOperators({ context, input, refDef }) {
18
- const operatorsParser = new BuildParser({
19
- env: process.env,
20
- operators
21
- });
22
- const { output, errors } = operatorsParser.parse({
15
+ */ async function evaluateBuildOperators({ context, input, refDef }) {
16
+ const { output, errors } = context.operatorsParser.parse({
23
17
  input,
24
18
  location: refDef.path ?? refDef.resolver,
25
19
  operatorPrefix: '_build.'
@@ -12,27 +12,47 @@
12
12
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
13
  See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
- */ import getConfigFile from './getConfigFile.js';
15
+ */ import { getFileExtension } from '@lowdefy/node-utils';
16
+ import getConfigFile from './getConfigFile.js';
16
17
  import parseRefContent from './parseRefContent.js';
17
18
  import runRefResolver from './runRefResolver.js';
19
+ function getCacheKey(refDef) {
20
+ const { path, vars } = refDef;
21
+ // For nunjucks files, vars affect the output, so include them in the cache key
22
+ const ext = getFileExtension(path);
23
+ if (ext === 'njk' && vars) {
24
+ return `${path}::${JSON.stringify(vars)}`;
25
+ }
26
+ return path;
27
+ }
18
28
  async function getRefContent({ context, refDef, referencedFrom }) {
19
- let content;
29
+ // Skip caching for resolver-based refs (dynamic content)
20
30
  if (refDef.resolver || context.refResolver) {
21
- content = await runRefResolver({
31
+ const content = await runRefResolver({
22
32
  context,
23
33
  refDef,
24
34
  referencedFrom
25
35
  });
26
- } else {
27
- content = await getConfigFile({
28
- context,
29
- refDef,
30
- referencedFrom
36
+ return parseRefContent({
37
+ content,
38
+ refDef
31
39
  });
32
40
  }
33
- return parseRefContent({
34
- content,
41
+ const cacheKey = getCacheKey(refDef);
42
+ const cached = context.parsedContentCache.get(cacheKey);
43
+ if (cached !== undefined) {
44
+ return cached;
45
+ }
46
+ const rawContent = await getConfigFile({
47
+ context,
48
+ refDef,
49
+ referencedFrom
50
+ });
51
+ const parsed = parseRefContent({
52
+ content: rawContent,
35
53
  refDef
36
54
  });
55
+ context.parsedContentCache.set(cacheKey, parsed);
56
+ return parsed;
37
57
  }
38
58
  export default getRefContent;
@@ -13,17 +13,25 @@
13
13
  See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
15
  */ import { mergeObjects } from '@lowdefy/helpers';
16
+ import { BuildParser } from '@lowdefy/operators';
17
+ import operators from '@lowdefy/operators-js/operators/build';
16
18
  import createCounter from './utils/createCounter.js';
17
19
  import createReadConfigFile from './utils/readConfigFile.js';
18
20
  import createWriteBuildArtifact from './utils/writeBuildArtifact.js';
19
21
  import defaultTypesMap from './defaultTypesMap.js';
20
22
  function createContext({ customTypesMap, directories, entitlements = [], logger, refResolver, stage = 'prod' }) {
23
+ const operatorsParser = new BuildParser({
24
+ env: process.env,
25
+ operators
26
+ });
21
27
  const context = {
22
28
  directories,
23
29
  entitlements,
24
30
  jsMap: {},
25
31
  keyMap: {},
26
32
  logger,
33
+ operatorsParser,
34
+ parsedContentCache: new Map(),
27
35
  readConfigFile: createReadConfigFile({
28
36
  directories
29
37
  }),