Skip to content

Commit

Permalink
Fix build
Browse files Browse the repository at this point in the history
  • Loading branch information
lukastaegert committed Aug 26, 2022
1 parent 8fbb38d commit 7852afe
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
4 changes: 2 additions & 2 deletions build-plugins/clean-before-write.ts
@@ -1,4 +1,4 @@
import { remove } from 'fs-extra';
import fs from 'fs-extra';
import type { Plugin } from 'rollup';

export default function cleanBeforeWrite(dir: string): Plugin {
Expand All @@ -7,7 +7,7 @@ export default function cleanBeforeWrite(dir: string): Plugin {
generateBundle(_options, _bundle, isWrite) {
if (isWrite) {
// Only remove before first write, but make all writes wait on the removal
removePromise ||= remove(dir);
removePromise ||= fs.remove(dir);
return removePromise;
}
},
Expand Down
4 changes: 2 additions & 2 deletions build-plugins/copy-types.ts
@@ -1,5 +1,5 @@
import { resolve } from 'node:path';
import { readFile } from 'fs-extra';
import fs from 'fs-extra';
import type { Plugin } from 'rollup';

export default function copyTypes(fileName: string): Plugin {
Expand All @@ -8,7 +8,7 @@ export default function copyTypes(fileName: string): Plugin {
if (isWrite) {
this.emitFile({
fileName,
source: await readFile(resolve('src/rollup/types.d.ts'), 'utf8'),
source: await fs.readFile(resolve('src/rollup/types.d.ts'), 'utf8'),
type: 'asset'
});
}
Expand Down
11 changes: 6 additions & 5 deletions build-plugins/get-banner.ts
@@ -1,11 +1,11 @@
import { exec } from 'node:child_process';
import { promises as fs } from 'node:fs';
import { env } from 'node:process';
import { promisify } from 'node:util';
import { version } from '../package.json';

const execPromise = promisify(exec);

function generateBanner(commitHash: string): string {
function generateBanner(commitHash: string, version: string): string {
const date = new Date(
env.SOURCE_DATE_EPOCH ? 1000 * +env.SOURCE_DATE_EPOCH : Date.now()
).toUTCString();
Expand All @@ -24,7 +24,8 @@ function generateBanner(commitHash: string): string {
let getBannerPromise: Promise<string> | null = null;

export default async function getBanner(): Promise<string> {
return (getBannerPromise ||= execPromise('git rev-parse HEAD').then(({ stdout }) =>
generateBanner(stdout.trim())
));
return (getBannerPromise ||= Promise.all([
execPromise('git rev-parse HEAD'),
fs.readFile(new URL('../package.json', import.meta.url), 'utf8')
]).then(([{ stdout }, pkg]) => generateBanner(stdout.trim(), JSON.parse(pkg).version)));
}

0 comments on commit 7852afe

Please sign in to comment.