mirror of
https://github.com/withastro/astro.git
synced 2024-12-16 21:46:22 -05:00
[ci] format
This commit is contained in:
parent
2aec2cdc21
commit
123f6f8551
4 changed files with 22 additions and 17 deletions
|
@ -67,7 +67,7 @@ export const getVersion = (packageManager: string, packageName: string, fallback
|
|||
redirect: 'follow',
|
||||
})
|
||||
.then((res) => res.json())
|
||||
.catch(() => ({ version: fallback }))
|
||||
.catch(() => ({ version: fallback }));
|
||||
return resolve(version);
|
||||
});
|
||||
|
||||
|
|
|
@ -124,7 +124,9 @@ describe('typescript: setup package', async () => {
|
|||
);
|
||||
|
||||
await setupTypeScript('strictest', { cwd: fileURLToPath(root), install: false });
|
||||
const { scripts, dependencies } = JSON.parse(fs.readFileSync(packageJson, { encoding: 'utf-8' }));
|
||||
const { scripts, dependencies } = JSON.parse(
|
||||
fs.readFileSync(packageJson, { encoding: 'utf-8' })
|
||||
);
|
||||
|
||||
assert.deepEqual(
|
||||
Object.keys(scripts),
|
||||
|
@ -133,7 +135,7 @@ describe('typescript: setup package', async () => {
|
|||
);
|
||||
|
||||
for (const value of Object.values(dependencies)) {
|
||||
assert.doesNotMatch(value, /undefined$/, 'does not include undefined values')
|
||||
assert.doesNotMatch(value, /undefined$/, 'does not include undefined values');
|
||||
}
|
||||
|
||||
assert.equal(scripts.build, 'astro check && astro build', 'prepends astro check command');
|
||||
|
|
|
@ -48,7 +48,7 @@ const resetNotEmptyFixture = async () => {
|
|||
build: 'astro build',
|
||||
preview: 'astro preview',
|
||||
},
|
||||
dependencies: undefined
|
||||
dependencies: undefined,
|
||||
});
|
||||
|
||||
return Promise.all([
|
||||
|
|
|
@ -53,10 +53,7 @@ export default async function build(...args) {
|
|||
const forceCJS = args.includes('--force-cjs');
|
||||
const copyWASM = args.includes('--copy-wasm');
|
||||
|
||||
const {
|
||||
type = 'module',
|
||||
dependencies = {},
|
||||
} = await readPackageJSON('./package.json');
|
||||
const { type = 'module', dependencies = {} } = await readPackageJSON('./package.json');
|
||||
|
||||
config.define = {};
|
||||
for (const [key, value] of await getDefinedEntries()) {
|
||||
|
@ -141,21 +138,23 @@ async function clean(outdir) {
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Contextual `define` values to statically replace in the built JS output.
|
||||
* Available to all packages, but mostly useful for CLIs like `create-astro`.
|
||||
*/
|
||||
/**
|
||||
* Contextual `define` values to statically replace in the built JS output.
|
||||
* Available to all packages, but mostly useful for CLIs like `create-astro`.
|
||||
*/
|
||||
async function getDefinedEntries() {
|
||||
const define = {
|
||||
/** The current version (at the time of building) for the current package, such as `astro` or `@astrojs/sitemap` */
|
||||
PACKAGE_VERSION: await getInternalPackageVersion('./package.json'),
|
||||
/** The current version (at the time of building) for `astro` */
|
||||
ASTRO_VERSION: await getInternalPackageVersion(new URL('../../packages/astro/package.json', import.meta.url)),
|
||||
ASTRO_VERSION: await getInternalPackageVersion(
|
||||
new URL('../../packages/astro/package.json', import.meta.url)
|
||||
),
|
||||
/** The current version (at the time of building) for `@astrojs/check` */
|
||||
ASTRO_CHECK_VERSION: await getWorkspacePackageVersion('@astrojs/check'),
|
||||
/** The current version (at the time of building) for `typescript` */
|
||||
TYPESCRIPT_VERSION: await getWorkspacePackageVersion('typescript'),
|
||||
}
|
||||
};
|
||||
for (const [key, value] of Object.entries(define)) {
|
||||
if (value === undefined) {
|
||||
delete define[key];
|
||||
|
@ -169,15 +168,19 @@ async function readPackageJSON(path) {
|
|||
}
|
||||
|
||||
async function getInternalPackageVersion(path) {
|
||||
return readPackageJSON(path).then(res => res.version);
|
||||
return readPackageJSON(path).then((res) => res.version);
|
||||
}
|
||||
|
||||
async function getWorkspacePackageVersion(packageName) {
|
||||
const { dependencies, devDependencies } = await readPackageJSON(new URL('../../package.json', import.meta.url));
|
||||
const { dependencies, devDependencies } = await readPackageJSON(
|
||||
new URL('../../package.json', import.meta.url)
|
||||
);
|
||||
const deps = { ...dependencies, ...devDependencies };
|
||||
const version = deps[packageName];
|
||||
if (!version) {
|
||||
throw new Error(`Unable to resolve "${packageName}". Is it a depdendency of the workspace root?`)
|
||||
throw new Error(
|
||||
`Unable to resolve "${packageName}". Is it a depdendency of the workspace root?`
|
||||
);
|
||||
}
|
||||
return version.replace(/^\D+/, '');
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue