Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .github/actions/install-npm/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Install NPM
description: >
Installs the NPM version required by the `engines.npm` directive in
package.json, which is required for the project to build correctly.

runs:
using: composite
steps:
- name: Install NPM
shell: bash
run: |
npmVersion="$(node -p 'require(`${process.env.GITHUB_WORKSPACE}/package.json`).engines.npm')"
echo "Installing npm@${npmVersion}"
npm install -g "npm@${npmVersion}"
5 changes: 4 additions & 1 deletion .github/workflows/bootstrap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,12 @@ jobs:

- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
with:
node-version: "22.x"
node-version: ">=24.18.1 <25"
cache: "npm"

- name: Install NPM version specified in package.json
uses: ./.github/actions/install-npm

- name: Install dependencies
run: npm ci --no-audit

Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,12 @@ jobs:

- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
with:
node-version: "22.x"
node-version: ">=24.18.1 <25"
cache: "npm"

- name: Install NPM version specified in package.json
uses: ./.github/actions/install-npm

- name: Install dependencies
run: npm ci --no-audit

Expand Down
7 changes: 5 additions & 2 deletions .github/workflows/test-and-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ name: Test and Release
permissions:
contents: write
issues: write
id-token: write

on:
push:

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

jobs:
test:
Expand All @@ -20,9 +20,12 @@ jobs:

- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
with:
node-version: "22.x"
node-version: ">=24.18.1 <25"
cache: "npm"

- name: Install NPM version specified in package.json
uses: ./.github/actions/install-npm

- name: Install dependencies
run: npm ci --no-audit

Expand Down
47 changes: 47 additions & 0 deletions .npm/compile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Compile source for NPM
*/

import swc from '@swc/core'
import { mkdirSync, rmSync, writeFileSync } from 'node:fs'
import { glob } from 'node:fs/promises'
import path, { dirname } from 'node:path'
import { fileURLToPath } from 'node:url'
import { updateImports } from './updateImports.ts'

const __dirname = dirname(fileURLToPath(import.meta.url))

const outDir = path.join(__dirname, '..', 'dist')

try {
rmSync(outDir, { recursive: true, force: true })
} catch {
// pass
}

for await (const file of glob(`./cdk/*.ts`)) {
if (file.endsWith('.spec.ts')) continue
let compiled = (
await swc.transformFile(file, {
jsc: {
parser: {
syntax: 'typescript',
},
target: 'es2024',
},
module: {
type: 'es6',
},
})
).code

compiled = updateImports(compiled)

const targetFile = path.join(outDir, file.replace(/\.ts$/, '.js'))

mkdirSync(dirname(targetFile), { recursive: true })

writeFileSync(targetFile, compiled, 'utf8')

console.log(file)
}
9 changes: 9 additions & 0 deletions .npm/tsconfig.npm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"emitDeclarationOnly": true,
"declaration": true,
"noEmit": false
},
"include": ["../cdk"]
}
11 changes: 11 additions & 0 deletions .npm/updateImports.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import assert from 'node:assert'
import { describe, it } from 'node:test'
import { updateImports } from './updateImports.ts'

void describe('updateImports', () => {
void it('replaces .ts with .js in relative imports', () => {
const input = `import { foo } from './bar.ts';`
const expected = `import { foo } from './bar.js';`
assert.equal(updateImports(input), expected)
})
})
2 changes: 2 additions & 0 deletions .npm/updateImports.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const updateImports = (source: string): string =>
source.replace(/from ['"](.+?)\.ts['"]/g, "from '$1.js'")
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
PBSD 3-Clause License

Copyright (c) 2023-2025, Nordic Semiconductor ASA | nordicsemi.no
Copyright (c) 2023-2026, Nordic Semiconductor ASA | nordicsemi.no
All rights reserved.

Redistribution and use in source and binary forms, with or without
Expand Down
2 changes: 1 addition & 1 deletion cdk.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"app": "npx tsx --no-warnings cdk/ci.ts"
"app": "node --experimental-transform-types --no-warnings cdk/ci.ts"
}
2 changes: 1 addition & 1 deletion cdk/CIApp.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { App } from 'aws-cdk-lib'
import { CIStack } from './CIStack.js'
import { CIStack } from './CIStack.ts'

export class CIApp extends App {
public constructor(
Expand Down
4 changes: 2 additions & 2 deletions cdk/CIStack.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { App } from 'aws-cdk-lib'
import { CfnOutput, Stack } from 'aws-cdk-lib'
import { RepoPermission } from './RepoPermission.js'
import type { Repos } from './listRepos.js'
import { RepoPermission } from './RepoPermission.ts'
import type { Repos } from './listRepos.ts'

export class CIStack extends Stack {
public constructor(
Expand Down
4 changes: 2 additions & 2 deletions cdk/RepoPermission.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Duration, aws_iam as IAM, Stack } from 'aws-cdk-lib'
import { Construct } from 'constructs'
import type { Repository } from './listRepos.js'
import { sanitize } from './sanitize.js'
import type { Repository } from './listRepos.ts'
import { sanitize } from './sanitize.ts'

export class RepoPermission extends Construct {
public readonly role: IAM.IRole
Expand Down
8 changes: 4 additions & 4 deletions cdk/ci.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { IAMClient } from '@aws-sdk/client-iam'
import { fromEnv } from '@bifravst/from-env'
import { CIApp } from './CIApp.js'
import { ensureGitHubOIDCProvider } from './ensureGitHubOIDCProvider.js'
import { listRepos } from './listRepos.js'
import { loadRepoList } from './loadRepoList.js'
import { CIApp } from './CIApp.ts'
import { ensureGitHubOIDCProvider } from './ensureGitHubOIDCProvider.ts'
import { listRepos } from './listRepos.ts'
import { loadRepoList } from './loadRepoList.ts'

const { token } = fromEnv({
token: 'GITHUB_TOKEN',
Expand Down
6 changes: 3 additions & 3 deletions cdk/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export * from './ContinuousDeployment.js'
export * from './ensureGitHubOIDCProvider.js'
export * from './RepoPermission.js'
export * from './ContinuousDeployment.ts'
export * from './ensureGitHubOIDCProvider.ts'
export * from './RepoPermission.ts'
2 changes: 1 addition & 1 deletion cdk/loadRepoList.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import assert from 'node:assert/strict'
import path from 'node:path'
import { describe, it } from 'node:test'
import { loadRepoList } from './loadRepoList.js'
import { loadRepoList } from './loadRepoList.ts'

void describe('loadRepoList()', () => {
void it('should load the list of repos', async () => {
Expand Down
2 changes: 1 addition & 1 deletion cdk/loadRepoList.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { readFile } from 'node:fs/promises'
import type { Repository } from './listRepos.js'
import type { Repository } from './listRepos.ts'

export const loadRepoList = async (
location: string,
Expand Down
Loading
Loading