Skip to content

Commit

Permalink
build: allow the package to be used as a git npm dependency (#132)
Browse files Browse the repository at this point in the history
  • Loading branch information
divdavem committed Jun 6, 2024
1 parent dbcbf8c commit fcae275
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 55 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,10 @@ jobs:
git config --global user.name github-actions
git config --global user.email github-actions@github.com
- name: npm version
working-directory: src
if: inputs.version != 'doconly'
run: |
npm version ${{ inputs.version }}
git add package.json
git add package.json package-lock.json
git commit -m v${{ inputs.version }}
git tag v${{ inputs.version }}
- run: git show HEAD
Expand Down
3 changes: 3 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 44 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,44 @@
{
"name": "@amadeus-it-group/tansu",
"type": "module",
"version": "1.0.0",
"description": "tansu is a lightweight, push-based framework-agnostic state management library. It borrows the ideas and APIs originally designed and implemented by Svelte stores and extends them with computed and batch.",
"keywords": [
"signals",
"signal",
"agnostic",
"reactive",
"store",
"state",
"model",
"interop",
"observable",
"computed",
"derived",
"readable",
"writable",
"svelte",
"state management",
"angular"
],
"typings": "./dist/package/index.d.ts",
"main": "./dist/package/index.cjs",
"module": "./dist/package/index.js",
"exports": {
"types": "./dist/package/index.d.ts",
"require": "./dist/package/index.cjs",
"default": "./dist/package/index.js"
},
"license": "MIT",
"repository": {
"type": "git",
"url": "git+https://github.com/AmadeusITGroup/tansu.git"
},
"bugs": {
"url": "https://github.com/AmadeusITGroup/tansu/issues"
},
"homepage": "https://github.com/AmadeusITGroup/tansu#readme",
"private": true,
"devDependencies": {
"@angular/common": "^18.0.1",
"@angular/compiler": "^18.0.1",
Expand Down Expand Up @@ -39,8 +77,8 @@
"build:rollup": "rollup --failAfterWarnings -c",
"build:dts": "tsc -p tsconfig.d.json",
"build:api": "api-extractor run",
"build:package": "cp README.md src/package.json dist/package",
"build": "npm run clean && npm run build:rollup && npm run build:dts && npm run build:api && npm run build:package",
"build": "npm run clean && npm run build:rollup && npm run build:dts && npm run build:api",
"prepare": "npm run build",
"format:check": "prettier --check .",
"format:fix": "prettier --write .",
"docs": "typedoc"
Expand All @@ -55,5 +93,8 @@
"extends": [
"@commitlint/config-conventional"
]
}
},
"files": [
"dist/package"
]
}
68 changes: 53 additions & 15 deletions rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -1,18 +1,56 @@
import typescript from '@rollup/plugin-typescript';
import assert from 'assert';
import { readFile } from 'fs/promises';
import { defineConfig } from 'rollup';

export default [
{
output: [
{
file: './dist/package/index.cjs.js',
format: 'cjs',
},
{
file: './dist/package/index.es.js',
format: 'es',
const distPackagePrefix = './dist/package/';
const removeDistPackage = (withDistPackage) => {
assert(withDistPackage.startsWith(distPackagePrefix));
return `./${withDistPackage.substring(distPackagePrefix.length)}`;
};

export default defineConfig({
output: [
{
format: 'cjs',
file: './dist/package/index.cjs',
},
{
format: 'es',
file: './dist/package/index.js',
},
],
input: './src/index.ts',
plugins: [
typescript(),
{
name: 'package',
async buildStart() {
const pkg = JSON.parse(await readFile('./package.json', 'utf8'));
delete pkg.private;
delete pkg.devDependencies;
delete pkg.scripts;
delete pkg.husky;
delete pkg.commitlint;
delete pkg.files;
pkg.typings = removeDistPackage(pkg.typings);
pkg.main = removeDistPackage(pkg.main);
pkg.module = removeDistPackage(pkg.module);
pkg.exports.types = removeDistPackage(pkg.exports.types);
pkg.exports.require = removeDistPackage(pkg.exports.require);
pkg.exports.default = removeDistPackage(pkg.exports.default);
this.emitFile({ type: 'asset', fileName: 'package.json', source: JSON.stringify(pkg) });
this.emitFile({
type: 'asset',
fileName: 'README.md',
source: await readFile('README.md', 'utf-8'),
});
this.emitFile({
type: 'asset',
fileName: 'LICENSE',
source: await readFile('LICENSE', 'utf-8'),
});
},
],
input: './src/index.ts',
plugins: [typescript()],
},
];
},
],
});
35 changes: 0 additions & 35 deletions src/package.json

This file was deleted.

0 comments on commit fcae275

Please sign in to comment.