Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: make the export-dynamic-plugin command more generic for backend plugins. #967

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 20 additions & 12 deletions packages/cli/src/commands/export-dynamic-plugin/backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ import fs from 'fs-extra';
import { rollup } from 'rollup';
import * as semver from 'semver';

import { execSync } from 'child_process';
import path, { basename } from 'path';

import { Output } from '../../lib/builder';
import { makeRollupConfigs } from '../../lib/builder/config';
import { embedModules } from '../../lib/builder/embedPlugin';
import { buildPackage, formatErrorMessage } from '../../lib/builder/packager';
import { loadCliConfig } from '../../lib/config';
import { readEntryPoints } from '../../lib/entryPoints';
import { productionPack } from '../../lib/packager/productionPack';
import { paths } from '../../lib/paths';
import { Task } from '../../lib/tasks';
Expand All @@ -38,8 +40,8 @@ export async function backend(
opts: OptionValues,
): Promise<void> {
if (!fs.existsSync(paths.resolveTarget('src', 'dynamic'))) {
throw new Error(
`Package doesn't seem to support dynamic loading. It should have a src/dynamic folder, containing the dynamic loading entrypoints.`,
console.warn(
`Package doesn't seem to provide dynamic loading entrypoints. You might want to add dynamic loading entrypoints in a src/dynamic folder.`,
);
}

Expand All @@ -65,13 +67,18 @@ export async function backend(

const target = path.join(paths.targetDir, 'dist-dynamic');

if (
!pkg.files?.includes('dist-dynamic/*.*') ||
!pkg.files?.includes('dist-dynamic/dist/**') ||
!pkg.files?.includes('dist-dynamic/alpha/*')
) {
throw new Error(
`Package doesn't seem to support dynamic loading: its "files" property should include the following entries: ["dist-dynamic/*.*", "dist-dynamic/dist/**", "dist-dynamic/alpha/*"].`,
const requiredFiles = ['dist-dynamic/*.*', 'dist-dynamic/dist/**'];

const entryPoints = readEntryPoints(pkg);
if (entryPoints.find(e => e.mount === './alpha')) {
requiredFiles.push('dist-dynamic/alpha/*');
}

if (requiredFiles.some(f => !pkg.files?.includes(f))) {
console.warn(
`Package doesn't seem to fully support dynamic loading: its "files" property should include the following entries: [${requiredFiles
.map(f => `"${f}"`)
.join(', ')}].`,
);
}

Expand Down Expand Up @@ -332,9 +339,10 @@ export async function backend(
}

if (opts.install) {
const yarnInstall = `yarn install --production${
yarnLockExists ? ' --frozen-lockfile' : ''
}`;
const version = execSync('yarn --version').toString().trim();
const yarnInstall = version.startsWith('1.')
? `yarn install --production${yarnLockExists ? ' --frozen-lockfile' : ''}`
: `yarn install${yarnLockExists ? ' --immutable' : ''}`;

await Task.forCommand(yarnInstall, { cwd: target, optional: false });
await fs.remove(paths.resolveTarget('dist-dynamic', '.yarn'));
Expand Down