@o3r/pipeline 11.5.0-prerelease.4 → 11.5.0-prerelease.41

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@o3r/pipeline",
3
- "version": "11.5.0-prerelease.4",
3
+ "version": "11.5.0-prerelease.41",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -39,15 +39,23 @@
39
39
  "tslib": "^2.6.2"
40
40
  },
41
41
  "peerDependencies": {
42
- "@o3r/schematics": "^11.5.0-prerelease.4",
43
- "@o3r/telemetry": "^11.5.0-prerelease.4"
42
+ "@angular-devkit/schematics": "~18.2.0",
43
+ "@o3r/schematics": "^11.5.0-prerelease.41",
44
+ "@o3r/telemetry": "^11.5.0-prerelease.41",
45
+ "type-fest": "^4.10.2"
44
46
  },
45
47
  "peerDependenciesMeta": {
48
+ "@angular-devkit/schematics": {
49
+ "optional": true
50
+ },
46
51
  "@o3r/schematics": {
47
52
  "optional": true
48
53
  },
49
54
  "@o3r/telemetry": {
50
55
  "optional": true
56
+ },
57
+ "type-fest": {
58
+ "optional": true
51
59
  }
52
60
  },
53
61
  "devDependencies": {
@@ -59,11 +67,11 @@
59
67
  "@nx/eslint-plugin": "~19.5.0",
60
68
  "@nx/jest": "~19.5.0",
61
69
  "@nx/js": "~19.5.0",
62
- "@o3r/build-helpers": "^11.5.0-prerelease.4",
63
- "@o3r/eslint-plugin": "^11.5.0-prerelease.4",
64
- "@o3r/schematics": "^11.5.0-prerelease.4",
65
- "@o3r/telemetry": "^11.5.0-prerelease.4",
66
- "@o3r/test-helpers": "^11.5.0-prerelease.4",
70
+ "@o3r/build-helpers": "^11.5.0-prerelease.41",
71
+ "@o3r/eslint-plugin": "^11.5.0-prerelease.41",
72
+ "@o3r/schematics": "^11.5.0-prerelease.41",
73
+ "@o3r/telemetry": "^11.5.0-prerelease.41",
74
+ "@o3r/test-helpers": "^11.5.0-prerelease.41",
67
75
  "@schematics/angular": "~18.2.0",
68
76
  "@stylistic/eslint-plugin-ts": "~2.4.0",
69
77
  "@types/jest": "~29.5.2",
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../schematics/ng-add/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgD,IAAI,EAAiB,MAAM,4BAA4B,CAAC;AAC/G,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAyEtD;;;GAGG;AACH,eAAO,MAAM,KAAK,YAAa,qBAAqB,KAAG,IAQtD,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../schematics/ng-add/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgD,IAAI,EAA4B,MAAM,4BAA4B,CAAC;AAK1H,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAqFtD;;;GAGG;AACH,eAAO,MAAM,KAAK,YAAa,qBAAqB,KAAG,IAQtD,CAAC"}
@@ -3,8 +3,20 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ngAdd = void 0;
4
4
  const schematics_1 = require("@angular-devkit/schematics");
5
5
  const js_yaml_1 = require("js-yaml");
6
- const path = require("node:path");
7
6
  const fs = require("node:fs");
7
+ const path = require("node:path");
8
+ /**
9
+ * Determines if the Yarn version is 2 or higher based on the contents of the .yarnrc.yml file.
10
+ * @param tree tree
11
+ */
12
+ function isYarn2(tree) {
13
+ const yarnrcPath = '/.yarnrc.yml';
14
+ if (tree.exists(yarnrcPath)) {
15
+ const { yarnPath } = ((0, js_yaml_1.load)(tree.readText(yarnrcPath)) || {});
16
+ return !yarnPath || !/yarn-1\./.test(yarnPath);
17
+ }
18
+ return false;
19
+ }
8
20
  /**
9
21
  * Add an Otter CI pipeline to an Angular Project
10
22
  * @param options
@@ -13,9 +25,9 @@ function ngAddFn(options) {
13
25
  return async (tree, context) => {
14
26
  const packageJsonPath = path.resolve(__dirname, '..', '..', 'package.json');
15
27
  const ownPackageJson = JSON.parse(fs.readFileSync(packageJsonPath, { encoding: 'utf8' }));
16
- const commitHash = ownPackageJson.o3rConfig?.commitHash;
28
+ const commitHash = ownPackageJson.config?.o3r?.commitHash;
17
29
  const ownVersion = ownPackageJson.version;
18
- const actionVersionString = commitHash ? `${commitHash} # v${ownVersion}` : ownVersion;
30
+ const actionVersionString = commitHash ? `${commitHash} # v${ownVersion}` : `v${ownVersion}`;
19
31
  let packageManager = 'npm';
20
32
  try {
21
33
  const schematics = await Promise.resolve().then(() => require('@o3r/schematics'));
@@ -26,12 +38,14 @@ function ngAddFn(options) {
26
38
  }
27
39
  context.logger.info(`Setting up pipeline for package manager: "${packageManager}" `);
28
40
  const setupCommand = packageManager === 'yarn' ? 'yarn install --immutable' : 'npm ci';
41
+ const yarn2 = packageManager === 'yarn' && isYarn2(tree);
29
42
  const baseTemplateSource = (0, schematics_1.apply)((0, schematics_1.url)(`./templates/${options.toolchain}`), [
30
43
  (0, schematics_1.template)({
31
44
  ...options,
32
45
  packageManager,
33
46
  setupCommand,
34
47
  actionVersionString,
48
+ yarn2,
35
49
  dot: '.'
36
50
  }),
37
51
  (0, schematics_1.move)(tree.root.path)
@@ -40,26 +54,26 @@ function ngAddFn(options) {
40
54
  if (!options.npmRegistry) {
41
55
  return tree;
42
56
  }
43
- if (packageManager === 'yarn') {
57
+ if (yarn2) {
44
58
  const yarnrcPath = '/.yarnrc.yml';
45
- if (!tree.exists(yarnrcPath)) {
46
- tree.create(yarnrcPath, (0, js_yaml_1.dump)({ 'npmRegistryServer': options.npmRegistry }, { indent: 2 }));
47
- }
48
- else {
49
- const yarnrcContent = (0, js_yaml_1.load)(tree.readText(yarnrcPath));
50
- yarnrcContent.npmRegistryServer = options.npmRegistry;
51
- tree.overwrite(yarnrcPath, (0, js_yaml_1.dump)(yarnrcContent, { indent: 2 }));
52
- }
59
+ const yarnrcContent = (0, js_yaml_1.load)(tree.readText(yarnrcPath));
60
+ yarnrcContent.npmRegistryServer = options.npmRegistry;
61
+ tree.overwrite(yarnrcPath, (0, js_yaml_1.dump)(yarnrcContent, { indent: 2 }));
53
62
  }
54
- else if (packageManager === 'npm') {
63
+ else {
64
+ // both npm and yarn 1 use .npmrc for the registry
55
65
  const npmrcPath = '/.npmrc';
56
- const npmRegistry = `registry=${options.npmRegistry}`;
57
66
  if (!tree.exists(npmrcPath)) {
58
- tree.create(npmrcPath, npmRegistry);
67
+ tree.create(npmrcPath, `registry=${options.npmRegistry}`);
59
68
  }
60
69
  else {
61
70
  const npmrcContent = tree.readText(npmrcPath);
62
- tree.overwrite(npmrcPath, npmrcContent.concat(`\n${npmRegistry}`));
71
+ const registryPattern = /^registry=.*$/m;
72
+ const newRegistryLine = `registry=${options.npmRegistry}`;
73
+ const newContent = registryPattern.test(npmrcContent)
74
+ ? npmrcContent.replace(registryPattern, newRegistryLine)
75
+ : `${npmrcContent}\n${newRegistryLine}`;
76
+ tree.overwrite(npmrcPath, newContent);
63
77
  }
64
78
  }
65
79
  return tree;
@@ -6,16 +6,30 @@ runs:
6
6
  steps:
7
7
  - uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
8
8
  with:
9
- node-version: 20
10
- cache: <%= packageManager %>
9
+ node-version: 20<% if (packageManager !== 'yarn') { %>
10
+ cache: <%= packageManager %><% } %>
11
11
  - name: Enable Corepack
12
12
  shell: bash
13
- run: corepack enable
14
- - name: Install
15
- <% if (npmRegistry) { %>
13
+ run: corepack enable<% if (packageManager === 'yarn') { %>
14
+ - name: Get yarn cache directory path
15
+ shell: bash
16
+ id: yarn-cache-dir-path
17
+ run: echo "dir=$(<% if (yarn2) { %>yarn config get cacheFolder<% } else { %>yarn cache dir<% } %>)" >> $GITHUB_OUTPUT
18
+ - name: Cache dependencies
19
+ uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a # v4.1.2
20
+ with:
21
+ path: |
22
+ ${{ steps.yarn-cache-dir-path.outputs.dir }}
23
+ <% if (yarn2) { %>.yarn/unplugged
24
+ .pnp.cjs
25
+ .pnp.loader.mjs<% } %>
26
+ key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }}
27
+ restore-keys: |
28
+ ${{ runner.os }}-yarn
29
+ ${{ runner.os }}<% } %>
30
+ - name: Install<% if (npmRegistry) { %>
16
31
  env:
17
32
  COREPACK_NPM_REGISTRY: <%= npmRegistry %>
18
- COREPACK_INTEGRITY_KEYS: ""
19
- <% } %>
33
+ COREPACK_INTEGRITY_KEYS: ""<% } %>
20
34
  shell: bash
21
35
  run: <%= setupCommand %>
@@ -45,12 +45,12 @@ jobs:
45
45
  contents: write
46
46
  runs-on: <%= runner %>
47
47
  outputs:
48
- nextVersionTag: ${{ steps.new-version.outputs.nextVersionTag }}
48
+ nextVersionTag: ${{ steps.newVersion.outputs.nextVersionTag }}
49
49
  steps:
50
50
  - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
51
51
  - name: New version
52
52
  if: github.event_name != 'merge_group'
53
- id: new-version
53
+ id: newVersion
54
54
  uses: AmadeusITGroup/otter/tools/github-actions/new-version@<%= actionVersionString %>
55
55
  with:
56
56
  defaultBranch: ${{ env.DEFAULT_BRANCH }}