From 7e9b3441eb17724a3edbc9aa57c13379eafca97f Mon Sep 17 00:00:00 2001 From: Kagami Sascha Rosylight Date: Sun, 9 Jul 2023 00:53:59 +0200 Subject: [PATCH] fix sw build --- locales/index.js | 2 +- packages/sw/build.js | 9 ++++++--- packages/sw/package.json | 3 ++- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/locales/index.js b/locales/index.js index a88b0c67ad..7801f1275b 100644 --- a/locales/index.js +++ b/locales/index.js @@ -51,7 +51,7 @@ const primaries = { // 何故か文字列にバックスペース文字が混入することがあり、YAMLが壊れるので取り除く const clean = (text) => text.replace(new RegExp(String.fromCodePoint(0x08), 'g'), ''); -const locales = languages.reduce((a, c) => (a[c] = yaml.load(clean(fs.readFileSync(`${__dirname}/${c}.yml`, 'utf-8'))) || {}, a), {}); +const locales = languages.reduce((a, c) => (a[c] = yaml.load(clean(fs.readFileSync(new URL(`${c}.yml`, import.meta.url), 'utf-8'))) || {}, a), {}); export default Object.entries(locales) .reduce((a, [k ,v]) => (a[k] = (() => { diff --git a/packages/sw/build.js b/packages/sw/build.js index ad16fb9497..5efab5713d 100644 --- a/packages/sw/build.js +++ b/packages/sw/build.js @@ -1,10 +1,13 @@ // @ts-check -const esbuild = require('esbuild'); -const locales = require('../../locales'); -const meta = require('../../package.json'); +import * as esbuild from 'esbuild'; +import locales from '../../locales/index.js'; +import meta from '../../package.json' assert { type: "json" }; +import { fileURLToPath } from 'node:url'; const watch = process.argv[2]?.includes('watch'); +const __dirname = fileURLToPath(new URL(".", import.meta.url)) + console.log('Starting SW building...'); /** @type {esbuild.BuildOptions} */ diff --git a/packages/sw/package.json b/packages/sw/package.json index a2bead3dd4..a60f8230c2 100644 --- a/packages/sw/package.json +++ b/packages/sw/package.json @@ -19,5 +19,6 @@ "eslint": "8.44.0", "eslint-plugin-import": "2.27.5", "typescript": "5.1.6" - } + }, + "type": "module" }