fix(core): remove hash prefix from cdn path (#5509)
The hash prefix will cause cache invalidate during deployment It's for debug purpose but I forgot to remove it
This commit is contained in:
@@ -18,7 +18,7 @@ import type { BuildFlags } from '@affine/cli/config';
|
|||||||
import { projectRoot } from '@affine/cli/config';
|
import { projectRoot } from '@affine/cli/config';
|
||||||
import { VanillaExtractPlugin } from '@vanilla-extract/webpack-plugin';
|
import { VanillaExtractPlugin } from '@vanilla-extract/webpack-plugin';
|
||||||
import type { RuntimeConfig } from '@affine/env/global';
|
import type { RuntimeConfig } from '@affine/env/global';
|
||||||
import { WebpackS3Plugin, gitShortHash } from './s3-plugin.js';
|
import { WebpackS3Plugin } from './s3-plugin.js';
|
||||||
|
|
||||||
const IN_CI = !!process.env.CI;
|
const IN_CI = !!process.env.CI;
|
||||||
|
|
||||||
@@ -81,9 +81,9 @@ export const getPublicPath = (buildFlags: BuildFlags) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (BUILD_TYPE === 'canary') {
|
if (BUILD_TYPE === 'canary') {
|
||||||
return `https://dev.affineassets.com/${gitShortHash()}/`;
|
return `https://dev.affineassets.com/`;
|
||||||
} else if (BUILD_TYPE === 'beta' || BUILD_TYPE === 'stable') {
|
} else if (BUILD_TYPE === 'beta' || BUILD_TYPE === 'stable') {
|
||||||
return `https://prod.affineassets.com/${gitShortHash()}/`;
|
return `https://prod.affineassets.com/`;
|
||||||
}
|
}
|
||||||
return publicPath;
|
return publicPath;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,24 +1,11 @@
|
|||||||
import { join } from 'node:path';
|
import { join } from 'node:path';
|
||||||
import { execSync } from 'node:child_process';
|
|
||||||
import { readFile } from 'node:fs/promises';
|
import { readFile } from 'node:fs/promises';
|
||||||
|
|
||||||
import type { PutObjectCommandInput } from '@aws-sdk/client-s3';
|
import type { PutObjectCommandInput } from '@aws-sdk/client-s3';
|
||||||
import { PutObjectCommand, S3Client } from '@aws-sdk/client-s3';
|
import { PutObjectCommand, S3Client } from '@aws-sdk/client-s3';
|
||||||
import { once } from 'lodash-es';
|
|
||||||
import { lookup } from 'mime-types';
|
import { lookup } from 'mime-types';
|
||||||
import type { Compiler, WebpackPluginInstance } from 'webpack';
|
import type { Compiler, WebpackPluginInstance } from 'webpack';
|
||||||
|
|
||||||
export const gitShortHash = once(() => {
|
|
||||||
const { GITHUB_SHA } = process.env;
|
|
||||||
if (GITHUB_SHA) {
|
|
||||||
return GITHUB_SHA.substring(0, 9);
|
|
||||||
}
|
|
||||||
const sha = execSync(`git rev-parse --short HEAD`, {
|
|
||||||
encoding: 'utf-8',
|
|
||||||
}).trim();
|
|
||||||
return sha;
|
|
||||||
});
|
|
||||||
|
|
||||||
export const R2_BUCKET =
|
export const R2_BUCKET =
|
||||||
process.env.R2_BUCKET! ??
|
process.env.R2_BUCKET! ??
|
||||||
(process.env.BUILD_TYPE === 'canary' ? 'assets-dev' : 'assets-prod');
|
(process.env.BUILD_TYPE === 'canary' ? 'assets-dev' : 'assets-prod');
|
||||||
@@ -45,7 +32,7 @@ export class WebpackS3Plugin implements WebpackPluginInstance {
|
|||||||
const putObjectCommandOptions: PutObjectCommandInput = {
|
const putObjectCommandOptions: PutObjectCommandInput = {
|
||||||
Body: assetSource,
|
Body: assetSource,
|
||||||
Bucket: R2_BUCKET,
|
Bucket: R2_BUCKET,
|
||||||
Key: join(gitShortHash(), asset),
|
Key: asset,
|
||||||
};
|
};
|
||||||
const contentType = lookup(asset);
|
const contentType = lookup(asset);
|
||||||
if (contentType) {
|
if (contentType) {
|
||||||
|
|||||||
@@ -1,14 +1,27 @@
|
|||||||
import { createConfiguration, rootPath } from './config.js';
|
import { execSync } from 'node:child_process';
|
||||||
import { merge } from 'webpack-merge';
|
|
||||||
import { join, resolve } from 'node:path';
|
import { join, resolve } from 'node:path';
|
||||||
|
|
||||||
|
import { once } from 'lodash-es';
|
||||||
|
import { merge } from 'webpack-merge';
|
||||||
import type { BuildFlags } from '@affine/cli/config';
|
import type { BuildFlags } from '@affine/cli/config';
|
||||||
import { getRuntimeConfig } from './runtime-config.js';
|
|
||||||
import HTMLPlugin from 'html-webpack-plugin';
|
import HTMLPlugin from 'html-webpack-plugin';
|
||||||
|
|
||||||
import { gitShortHash } from './s3-plugin.js';
|
import { getRuntimeConfig } from './runtime-config.js';
|
||||||
|
import { createConfiguration, rootPath } from './config.js';
|
||||||
|
|
||||||
const DESCRIPTION = `There can be more than Notion and Miro. AFFiNE is a next-gen knowledge base that brings planning, sorting and creating all together.`;
|
const DESCRIPTION = `There can be more than Notion and Miro. AFFiNE is a next-gen knowledge base that brings planning, sorting and creating all together.`;
|
||||||
|
|
||||||
|
const gitShortHash = once(() => {
|
||||||
|
const { GITHUB_SHA } = process.env;
|
||||||
|
if (GITHUB_SHA) {
|
||||||
|
return GITHUB_SHA.substring(0, 9);
|
||||||
|
}
|
||||||
|
const sha = execSync(`git rev-parse --short HEAD`, {
|
||||||
|
encoding: 'utf-8',
|
||||||
|
}).trim();
|
||||||
|
return sha;
|
||||||
|
});
|
||||||
|
|
||||||
export default async function (cli_env: any, _: any) {
|
export default async function (cli_env: any, _: any) {
|
||||||
const flags: BuildFlags = JSON.parse(
|
const flags: BuildFlags = JSON.parse(
|
||||||
Buffer.from(cli_env.flags, 'hex').toString('utf-8')
|
Buffer.from(cli_env.flags, 'hex').toString('utf-8')
|
||||||
|
|||||||
Reference in New Issue
Block a user