-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
👷 (packages) [DSDK-262]: Build packages and ready them for publishing (…
- Loading branch information
Showing
36 changed files
with
1,527 additions
and
820 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
name: publish npm packages | ||
on: | ||
push: | ||
branches: | ||
- develop | ||
|
||
env: | ||
FORCE_COLOR: "1" | ||
|
||
jobs: | ||
publish: | ||
environment: Production | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- uses: ./.github/actions/setup-toolchain-composite | ||
|
||
- name: install dependencies | ||
run: pnpm install | ||
|
||
- name: build libraries | ||
run: pnpm build | ||
|
||
- name: publish | ||
uses: changesets/action@v1 | ||
with: | ||
publish: pnpm release | ||
env: | ||
GITHUB_TOKEN: ${{ github.token }} | ||
NPM_TOKEN: ${{ secrets.NPMJS_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,8 +8,8 @@ | |
"apps/*" | ||
], | ||
"scripts": { | ||
"build": "turbo build --log-order=grouped", | ||
"dev": "turbo dev --log-order=grouped", | ||
"build": "turbo run build --log-order=grouped", | ||
"dev": "turbo run dev --filter=...device-sdk-sample", | ||
"lint": "turbo run lint --log-order=grouped", | ||
"lint:fix": "turbo run lint:fix --log-order=grouped", | ||
"prettier": "turbo run prettier --log-order=grouped", | ||
|
@@ -32,28 +32,25 @@ | |
"devDependencies": { | ||
"@changesets/changelog-github": "^0.5.0", | ||
"@changesets/cli": "^2.27.1", | ||
"@types/jest": "^29.5.11", | ||
"@types/node": "^20.10.6", | ||
"@types/jest": "^29.5.12", | ||
"@types/node": "^20.12.4", | ||
"concurrently": "^8.2.2", | ||
"danger": "^11.3.1", | ||
"eslint": "^8.56.0", | ||
"gitmoji-cli": "^9.1.0", | ||
"esbuild": "^0.20.2", | ||
"esbuild-plugin-d.ts": "^1.2.3", | ||
"eslint": "^8.57.0", | ||
"gitmoji-cli": "^9.2.0", | ||
"hygen": "^6.2.11", | ||
"jest": "^29.7.0", | ||
"lint-staged": "^15.2.0", | ||
"prettier": "^3.1.1", | ||
"prettier": "^3.2.5", | ||
"rimraf": "^5.0.5", | ||
"ts-jest": "^29.1.1", | ||
"turbo": "^1.12.3", | ||
"typescript": "^5.3.3", | ||
"ts-jest": "^29.1.2", | ||
"tsc-alias": "^1.8.8", | ||
"turbo": "^1.13.2", | ||
"typescript": "^5.4.4", | ||
"zx": "^7.2.3" | ||
}, | ||
"lint-staged": { | ||
"*.ts": [ | ||
"eslint --fix", | ||
"prettier --write" | ||
] | ||
}, | ||
"packageManager": "[email protected]", | ||
"packageManager": "[email protected]", | ||
"engines": { | ||
"node": ">=18" | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
const buildConfig = (config, packageJson) => ({ | ||
sourcemap: true, | ||
treeShaking: true, | ||
color: true, | ||
bundle: true, | ||
minify: true, | ||
...config, | ||
plugins: [...(config.plugins || [])], | ||
external: Object.keys(packageJson.dependencies || {}).concat( | ||
Object.keys(packageJson.peerDependencies || {}) | ||
), | ||
}); | ||
|
||
module.exports = buildConfig; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
const alias = require("./plugins/alias"); | ||
const copy = require("./plugins/copy"); | ||
const buildConfig = require("./config/common"); | ||
|
||
module.exports = { | ||
alias, | ||
copy, | ||
buildConfig, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"name": "@ledgerhq/esbuild-tools", | ||
"main": "index.js", | ||
"private": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
const path = require("path"); | ||
|
||
/** | ||
* Alias Plugin for Esbuild (copied from Ledger Live) | ||
* | ||
* Replace a string by another string in the import path, should match the same | ||
* config as the tsconfig.json paths. | ||
* @param {*} mappings | ||
* @example { "@root": path.join(__dirname, "..") } will replace root by the specicified path | ||
* @returns void | ||
*/ | ||
module.exports = (mappings) => ({ | ||
name: "Alias", | ||
setup(build) { | ||
Object.entries(mappings).forEach(([filter, mappings]) => { | ||
if (!Array.isArray(mappings)) { | ||
mappings = [mappings]; | ||
} | ||
|
||
const resolveCallback = async function (args) { | ||
if (args.resolveDir === "") { | ||
return; // Ignore unresolvable paths | ||
} | ||
|
||
const errors = []; | ||
|
||
for (const mapping of mappings) { | ||
const rawMappedPath = args.path.replace(filter, mapping); | ||
const relativeMappedPath = path | ||
.relative(args.resolveDir, rawMappedPath) | ||
// Fixes windows paths | ||
.replace(new RegExp("\\\\+", "g"), "/"); | ||
|
||
const mappedPath = relativeMappedPath.startsWith(".") | ||
? relativeMappedPath | ||
: `./${relativeMappedPath}`; | ||
|
||
let result = await build.resolve(mappedPath, { | ||
kind: "import-statement", | ||
resolveDir: args.resolveDir, | ||
}); | ||
|
||
if (result.errors.length > 0) { | ||
errors.push(...result.errors); | ||
result = await build.resolve(rawMappedPath, { | ||
kind: "import-statement", | ||
resolveDir: args.resolveDir, | ||
}); | ||
|
||
if (result.errors.length > 0) { | ||
errors.push(...result.errors); | ||
continue; | ||
} | ||
} | ||
|
||
return result; | ||
} | ||
|
||
return { errors }; | ||
}; | ||
|
||
build.onResolve({ filter: new RegExp(`^${filter}$`) }, resolveCallback); | ||
build.onResolve({ filter: new RegExp(`^${filter}/.+`) }, resolveCallback); | ||
}); | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
const fs = require("fs"); | ||
const path = require("path"); | ||
|
||
// Copy a folder and its contents recursively. | ||
function copyFolderRecursivelySync(source, target, options = {}) { | ||
if (!fs.existsSync(target)) { | ||
fs.mkdirSync(target, { recursive: true, ...options }); | ||
} | ||
|
||
if (fs.statSync(source).isDirectory()) { | ||
const files = fs.readdirSync(source); | ||
files.forEach(function (file) { | ||
var curSource = path.join(source, file); | ||
if (fs.statSync(curSource).isDirectory()) { | ||
copyFolderRecursivelySync(curSource, path.join(target, file)); | ||
} else { | ||
fs.copyFileSync(curSource, path.join(target, path.basename(file))); | ||
} | ||
}); | ||
} | ||
} | ||
|
||
module.exports = ({ patterns, options = {} }) => { | ||
return { | ||
name: "Copy", | ||
setup(build) { | ||
build.onEnd(({ errors }) => { | ||
if (errors.length && !options.skipOnError) { | ||
return; | ||
} | ||
|
||
const targetBase = | ||
build.initialOptions.outdir || | ||
path.dirname(build.initialOptions.outfile); | ||
|
||
patterns.forEach(({ from, to }) => { | ||
copyFolderRecursivelySync(from, path.join(targetBase, to), options); | ||
}); | ||
}); | ||
}, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#!/usr/bin/env zx | ||
import { build } from "esbuild"; | ||
import { alias, buildConfig } from "@ledgerhq/esbuild-tools"; | ||
import path from "node:path"; | ||
import dtsPlugin from "esbuild-plugin-d.ts"; | ||
import pkg from "../package.json" assert { type: "json" }; | ||
|
||
const root = path.join(__dirname, ".."); | ||
const srcRoot = path.join(root, "src"); | ||
const outdir = path.join(root, "lib"); | ||
const tsconfigEsm = path.join(root, "tsconfig.esm.json"); | ||
const tsconfigCjs = path.join(root, "tsconfig.cjs.json"); | ||
|
||
const conf = { | ||
entryPoints: [path.join(root, "index.ts")], | ||
plugins: [ | ||
alias({ | ||
"@root": root, | ||
"@internal": path.join(srcRoot, "internal"), | ||
"@api": path.join(srcRoot, "api"), | ||
}), | ||
], | ||
}; | ||
|
||
const common = buildConfig(conf, pkg); | ||
|
||
const buildEsm = async () => { | ||
const config = { | ||
...common, | ||
outdir: path.join(outdir, "esm"), | ||
format: "esm", | ||
tsconfig: tsconfigEsm, | ||
plugins: [ | ||
...common.plugins, | ||
dtsPlugin({ | ||
tsconfig: tsconfigEsm, | ||
}), | ||
], | ||
}; | ||
|
||
await build(config); | ||
}; | ||
|
||
const builCjs = async () => { | ||
const config = { | ||
...common, | ||
outdir: path.join(outdir, "cjs"), | ||
format: "cjs", | ||
tsconfig: tsconfigCjs, | ||
plugins: [ | ||
...common.plugins, | ||
dtsPlugin({ | ||
tsconfig: tsconfigCjs, | ||
}), | ||
], | ||
}; | ||
|
||
await build(config); | ||
}; | ||
|
||
const run = async () => await Promise.all([buildEsm(), builCjs()]); | ||
|
||
run().catch((e) => { | ||
console.error(e); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"exclude": ["src/**/*.test.ts", "jest.*.ts"], | ||
"compilerOptions": { | ||
"module": "commonjs", | ||
"moduleResolution": "node", | ||
"outDir": "./lib/cjs", | ||
"declarationDir": "./lib/cjs" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"exclude": ["src/**/*.test.ts", "jest.*.ts"], | ||
"compilerOptions": { | ||
"module": "esnext", | ||
"outDir": "./lib/esm", | ||
"declarationDir": "./lib/esm" | ||
} | ||
} |
Oops, something went wrong.