Skip to content

Commit

Permalink
Remove bundling, replace Rollup with tsup, add @arethetypeswrong/cli …
Browse files Browse the repository at this point in the history
…to pipeline
  • Loading branch information
dankochetov committed Oct 14, 2023
1 parent f0b7352 commit ea3bfe6
Show file tree
Hide file tree
Showing 36 changed files with 987 additions and 585 deletions.
45 changes: 31 additions & 14 deletions .github/workflows/release-feature-branch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,34 @@ jobs:
- name: Install dependencies
run: pnpm install

- name: Check preconditions
id: checks
shell: bash
working-directory: ${{ matrix.package }}
run: |
old_version="$(jq -r .version package.json)"
version="$old_version-$(git rev-parse --short HEAD)"
tag="${{ github.ref_name }}"
is_version_published="$(npm view ${{ matrix.package }} versions --json | jq -r '.[] | select(. == "'$version'") | . == "'$version'"')"
if [[ "$is_version_published" == "true" ]]; then
echo "\`${{ matrix.package }}@$version\` already published, adding tag \`$tag\`" >> $GITHUB_STEP_SUMMARY
npm dist-tag add ${{ matrix.package }}@$version $tag
else
{
echo "version=$version"
echo "tag=$tag"
echo "has_new_release=true"
} >> $GITHUB_OUTPUT
fi
- name: Build
if: steps.checks.outputs.has_new_release == 'true'
run: |
pnpm build
- name: Run tests
if: steps.checks.outputs.has_new_release == 'true'
env:
PG_CONNECTION_STRING: postgres://postgres:postgres@localhost:5432/drizzle
MYSQL_CONNECTION_STRING: mysql://root:root@localhost:3306/drizzle
Expand All @@ -100,22 +123,16 @@ jobs:
fi
- name: Publish
if: github.event_name == 'push'
if: github.event_name == 'push' && steps.checks.outputs.has_new_release == 'true'
run: |
tag="${{ github.ref_name }}"
old_version="$(jq -r .version package.json)"
version="$old_version-$(git rev-parse --short HEAD)"
is_version_published="$(npm view ${{ matrix.package }} versions --json | jq -r '.[] | select(. == "'$version'") | . == "'$version'"')"
tag="${{ steps.checks.outputs.tag }}"
version="${{ steps.checks.outputs.version }}"
if [[ "$is_version_published" == "true" ]]; then
echo "Version $version already published, adding tag $tag"
npm dist-tag add ${{ matrix.package }}@$version $tag
else
echo "Publishing ${{ matrix.package }}@$tag using version $version"
(cd dist && npm version $version)
npm run pack
npm run publish -- --tag $tag
fi
echo "Publishing ${{ matrix.package }}@$tag using version $version"
(cd dist && npm version $version)
npm run pack
npx attw package.tgz
npm run publish -- --tag $tag
echo "npm: \`${{ matrix.package }}@$tag | ${{ matrix.package }}@$version\`" >> $GITHUB_STEP_SUMMARY
Expand Down
37 changes: 26 additions & 11 deletions .github/workflows/release-latest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,12 @@ jobs:
run: |
latest="$(npm view --json ${{ matrix.package }} dist-tags.latest | jq -r)"
version="$(jq -r .version package.json)"
is_version_published="$(npm view ${{ matrix.package }} versions --json | jq -r '.[] | select(. == "'$version'") | . == "'$version'"')"
if [[ "$latest" != "$version" ]]; then
if [[ "$is_version_published" == "true" ]]; then
echo "\`${{ matrix.package }}@$version\` already published, adding tag \`latest\`" >> $GITHUB_STEP_SUMMARY
npm dist-tag add ${{ matrix.package }}@$version latest
elif [[ "$latest" != "$version" ]]; then
echo "Latest: $latest"
echo "Current: $version"
Expand Down Expand Up @@ -119,6 +123,24 @@ jobs:
pnpm test --filter ${{ matrix.package }}
fi
- name: Pack
if: steps.checks.outputs.has_new_release == 'true'
working-directory: ${{ matrix.package }}
shell: bash
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_ACCESS_TOKEN }}
run: |
npm run pack
- name: Running @arethetypeswrong/cli
if: steps.checks.outputs.has_new_release == 'true'
working-directory: ${{ matrix.package }}
shell: bash
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_ACCESS_TOKEN }}
run: |
pnpm attw package.tgz
- name: Publish
if: steps.checks.outputs.has_new_release == 'true'
working-directory: ${{ matrix.package }}
Expand All @@ -127,21 +149,14 @@ jobs:
NODE_AUTH_TOKEN: ${{ secrets.NPM_ACCESS_TOKEN }}
run: |
version="${{ steps.checks.outputs.version }}"
is_version_published="$(npm view ${{ matrix.package }} versions --json | jq -r '.[] | select(. == "'$version'") | . == "'$version'"')"
if [[ "$is_version_published" == "true" ]]; then
echo "Version $version already published, adding tag $tag"
npm dist-tag add ${{ matrix.package }}@$version latest
else
echo echo "Publishing ${{ matrix.package }}@$version"
npm run pack
npm run publish
fi
echo "Publishing ${{ matrix.package }}@$version"
npm run publish
echo "npm: \`+ ${{ matrix.package }}@$version\`" >> $GITHUB_STEP_SUMMARY
# Post release message to Discord
curl -X POST -H "Content-Type: application/json" -d "{\"embeds\": [{\"title\": \"New \`${{ matrix.package }}\` release! 🎉\", \"url\": \"https://www.npmjs.com/package/${{ matrix.package }}\", \"color\": \"12907856\", \"fields\": [{\"name\": \"Tag\", \"value\": \"\`$tag\`\"}]}]}" ${{ secrets.DISCORD_RELEASE_WEBHOOK_URL }}
# curl -X POST -H "Content-Type: application/json" -d "{\"embeds\": [{\"title\": \"New \`${{ matrix.package }}\` release! 🎉\", \"url\": \"https://www.npmjs.com/package/${{ matrix.package }}\", \"color\": \"12907856\", \"fields\": [{\"name\": \"Tag\", \"value\": \"\`$tag\`\"}]}]}" ${{ secrets.DISCORD_RELEASE_WEBHOOK_URL }}
- name: Create GitHub release for ORM package
uses: actions/github-script@v6
Expand Down
10 changes: 1 addition & 9 deletions drizzle-orm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"publish": "npm publish package.tgz"
},
"main": "./index.cjs",
"module": "./index.mjs",
"module": "./index.js",
"types": "./index.d.ts",
"sideEffects": false,
"publishConfig": {
Expand Down Expand Up @@ -130,9 +130,6 @@
"@opentelemetry/api": "^1.4.1",
"@originjs/vite-plugin-commonjs": "^1.0.3",
"@planetscale/database": "^1.7.0",
"@rollup/plugin-json": "^6.0.0",
"@rollup/plugin-replace": "^5.0.2",
"@rollup/plugin-typescript": "^11.1.1",
"@types/better-sqlite3": "^7.6.4",
"@types/node": "^20.2.5",
"@types/pg": "^8.10.1",
Expand All @@ -141,16 +138,11 @@
"better-sqlite3": "^8.4.0",
"bun-types": "^0.6.6",
"cpy": "^10.1.0",
"cpy-cli": "^5.0.0",
"knex": "^2.4.2",
"kysely": "^0.25.0",
"mysql2": "^3.3.3",
"pg": "^8.11.0",
"postgres": "^3.3.5",
"rimraf": "^5.0.0",
"rollup": "^3.27.2",
"rollup-plugin-dts": "^5.3.1",
"rollup-plugin-typescript2": "^0.35.0",
"sql.js": "^1.8.0",
"sqlite3": "^5.1.2",
"tslib": "^2.5.2",
Expand Down
39 changes: 0 additions & 39 deletions drizzle-orm/rollup.cjs.config.ts

This file was deleted.

63 changes: 0 additions & 63 deletions drizzle-orm/rollup.common.ts

This file was deleted.

34 changes: 0 additions & 34 deletions drizzle-orm/rollup.esm.config.ts

This file was deleted.

58 changes: 36 additions & 22 deletions drizzle-orm/scripts/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
import 'zx/globals';
import cpy from 'cpy';

import { entries } from '../rollup.common';
async function updateAndCopyPackageJson() {
const pkg = await fs.readJSON('package.json');

function updateAndCopyPackageJson() {
const pkg = fs.readJSONSync('package.json');
const entries = await glob('src/**/*.ts');

pkg.exports = entries.reduce<
Record<string, {
Expand All @@ -21,13 +21,14 @@ function updateAndCopyPackageJson() {
types: string;
}>
>(
(acc, entry) => {
(acc, rawEntry) => {
const entry = rawEntry.match(/src\/(.*)\.ts/)![1]!;
const exportsEntry = entry === 'index' ? '.' : './' + entry.replace(/\/index$/, '');
const importEntry = `./${entry}.mjs`;
const importEntry = `./${entry}.js`;
const requireEntry = `./${entry}.cjs`;
acc[exportsEntry] = {
import: {
types: `./${entry}.d.mts`,
types: `./${entry}.d.ts`,
default: importEntry,
},
require: {
Expand All @@ -42,21 +43,34 @@ function updateAndCopyPackageJson() {
{},
);

fs.writeJSONSync('dist.new/package.json', pkg, { spaces: 2 });
await fs.writeJSON('dist.new/package.json', pkg, { spaces: 2 });
}

await $`rollup --config rollup.cjs.config.ts --configPlugin typescript`;
await $`rollup --config rollup.esm.config.ts --configPlugin typescript`;
await $`rimraf dist-dts && tsc -p tsconfig.dts.json && resolve-tspaths -p tsconfig.dts.json --out dist-dts`;
await cpy('dist-dts/**/*.d.ts', 'dist.new', {
rename: (basename) => basename.replace(/\.d\.ts$/, '.d.mts'),
});
await cpy('dist-dts/**/*.d.ts', 'dist.new', {
rename: (basename) => basename.replace(/\.d\.ts$/, '.d.cts'),
});
await cpy('dist-dts/**/*.d.ts', 'dist.new');
fs.removeSync('dist-dts');
fs.copySync('../README.md', 'dist.new/README.md');
updateAndCopyPackageJson();
fs.removeSync('dist');
fs.renameSync('dist.new', 'dist');
await fs.remove('dist.new');

await Promise.all([
(async () => {
await $`tsup`;

await Promise.all([
$`tsup src/version.ts --no-config --dts --format esm --outDir dist.new`,
$`tsup src/version.ts --no-config --dts --format cjs --outDir dist.new`,
]);
})(),
(async () => {
await $`tsc -p tsconfig.dts.json`;
await cpy('dist-dts/**/*.d.ts', 'dist.new', {
rename: (basename) => basename.replace(/\.d\.ts$/, '.d.cts'),
});
await cpy('dist-dts/**/*.d.ts', 'dist.new', {
rename: (basename) => basename.replace(/\.d\.ts$/, '.d.ts'),
});
})(),
]);

await $`scripts/fix-imports.ts`;

await fs.copy('../README.md', 'dist.new/README.md');
await updateAndCopyPackageJson();
await fs.remove('dist');
await fs.rename('dist.new', 'dist');
Loading

0 comments on commit ea3bfe6

Please sign in to comment.