Skip to content

Commit

Permalink
Mostly finished updates.
Browse files Browse the repository at this point in the history
  • Loading branch information
seanparsons committed Jan 31, 2025
1 parent f80120d commit 345846b
Show file tree
Hide file tree
Showing 27 changed files with 6,127 additions and 16,029 deletions.
21,866 changes: 5,958 additions & 15,908 deletions package-lock.json

Large diffs are not rendered by default.

46 changes: 23 additions & 23 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,39 +22,39 @@
},
"devDependencies": {
"@remix-run/dev": "^2.15.2",
"@types/diff": "^7.0.0",
"@types/gunzip-maybe": "^1.4.2",
"@types/prettier": "^3.0.0",
"@types/diff": "^5.0.2",
"@types/gunzip-maybe": "^1.4.0",
"@types/prettier": "^2.7.2",
"@types/source-map-support": "^0.5.10",
"@types/tar-fs": "^2.0.4",
"@vitest/coverage-v8": "^3.0.4",
"devtools-protocol": "^0.0.1412693",
"fast-glob": "^3.3.3",
"flame-chart-js": "3.3.0",
"get-port": "^7.1.0",
"type-fest": "^4.33.0",
"vite": "^6.0.11",
"vitest": "^3.0.4"
"@types/tar-fs": "^2.0.1",
"@vitest/coverage-v8": "^1.0.4",
"devtools-protocol": "^0.0.1177611",
"fast-glob": "^3.2.12",
"flame-chart-js": "2.3.2",
"get-port": "^7.0.0",
"type-fest": "^4.26.1",
"vite": "^5.1.8",
"vitest": "^1.0.4"
},
"dependencies": {
"@ast-grep/napi": "0.34.3",
"@ast-grep/napi": "0.11.0",
"@oclif/core": "3.26.5",
"@shopify/cli-kit": "^3.74.1",
"@shopify/oxygen-cli": "4.6.7",
"@shopify/oxygen-cli": "4.6.6",
"@shopify/plugin-cloudflare": "^3.74.1",
"ansi-escapes": "^7.0.0",
"chokidar": "4.0.3",
"ansi-escapes": "^6.2.0",
"chokidar": "3.5.3",
"cli-truncate": "^4.0.0",
"diff": "^7.0.0",
"get-port": "^7.1.0",
"diff": "^5.1.0",
"get-port": "^7.0.0",
"gunzip-maybe": "^1.4.2",
"prettier": "^3.4.2",
"semver": "^7.6.3",
"prettier": "^2.8.4",
"semver": "^7.5.3",
"source-map": "^0.7.4",
"source-map-support": "^0.5.21",
"tar-fs": "^3.0.8",
"tempy": "3.1.0",
"ts-morph": "25.0.0",
"tar-fs": "^2.1.1",
"tempy": "3.0.0",
"ts-morph": "20.0.0",
"use-resize-observer": "^9.1.0"
},
"peerDependencies": {
Expand Down
17 changes: 8 additions & 9 deletions packages/cli/src/commands/hydrogen/setup/vite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,13 @@ export async function runSetupVite({directory}: {directory: string}) {
// Sort dependencies:
pkgJson.devDependencies = Object.keys(pkgJson.devDependencies)
.sort()
.reduce((acc, key) => {
acc[key] = pkgJson.devDependencies?.[key]!;
return acc;
}, {} as Record<string, string>);
.reduce(
(acc, key) => {
acc[key] = pkgJson.devDependencies?.[key]!;
return acc;
},
{} as Record<string, string>,
);
}
}

Expand Down Expand Up @@ -217,11 +220,7 @@ export async function runSetupVite({directory}: {directory: string}) {
'vite.config.' + fileExt.slice(0, 2),
);

viteConfigContent = await formatCode(
viteConfigContent,
formatOptions,
viteConfigPath,
);
viteConfigContent = await formatCode(viteConfigContent, formatOptions);

return writeFile(viteConfigPath, viteConfigContent);
},
Expand Down
3 changes: 3 additions & 0 deletions packages/cli/src/lib/classic-compiler/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,15 @@ export async function runClassicCompilerBuild({
lockfileCheck = true,
assetPath,
}: RunBuildOptions) {
console.log('runClassicCompilerBuild');
if (!process.env.NODE_ENV) {
process.env.NODE_ENV = 'production';
}
if (assetPath) {
process.env.HYDROGEN_ASSET_BASE_URL = assetPath;
}
console.log('directory', directory);
process.chdir(directory!);

const {root, buildPath, buildPathClient, buildPathWorkerFile, publicPath} =
getProjectPaths(directory);
Expand Down
6 changes: 5 additions & 1 deletion packages/cli/src/lib/classic-compiler/dev.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,19 @@ describe('Classic Remix Compiler dev', () => {
outputMock.clear();
vi.stubEnv('NODE_ENV', 'development');

console.log('runClassicCompilerDev starting');
process.chdir(tmpDir);
const {close, getUrl} = await runClassicCompilerDev({
path: tmpDir,
disableVirtualRoutes: true,
disableVersionCheck: true,
cliConfig: {} as any,
cliConfig: {root: tmpDir} as any,
envFile: '.env',
});
console.log('runClassicCompilerDev finished');

try {
console.log('outputMock.output()', outputMock.output());
await vi.waitFor(() => expect(outputMock.output()).toMatch('success'), {
timeout: 5000,
});
Expand Down
8 changes: 8 additions & 0 deletions packages/cli/src/lib/classic-compiler/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ export async function runClassicCompilerDev({
getProjectPaths(appPath);

const copyFilesPromise = copyPublicFiles(publicPath, buildPathClient);
console.log('root', root);
const cliCommandPromise = getCliCommand(root);

const reloadConfig = async () => {
Expand All @@ -119,6 +120,7 @@ export async function runClassicCompilerDev({
return [fileRelative, resolvePath(root, fileRelative)] as const;
};

console.log('buildPathWorkerFile', buildPathWorkerFile);
const serverBundleExists = () => fileExists(buildPathWorkerFile);

if (!appPort) {
Expand Down Expand Up @@ -154,6 +156,7 @@ export async function runClassicCompilerDev({
});

const remixConfig = await reloadConfig();
console.log('remixConfig', JSON.stringify(remixConfig, null, 2));
assertOxygenChecks(remixConfig);

const envPromise = backgroundPromise.then(({fetchRemote, localVariables}) =>
Expand Down Expand Up @@ -214,6 +217,7 @@ export async function runClassicCompilerDev({
const host = (await tunnelPromise)?.host ?? miniOxygen.listeningAt;

const cliCommand = await cliCommandPromise;
console.log('cliCommand', cliCommand);
enhanceH2Logs({host, cliCommand, ...remixConfig});

const {storefrontTitle} = await backgroundPromise;
Expand Down Expand Up @@ -261,6 +265,7 @@ export async function runClassicCompilerDev({
{
reloadConfig,
onBuildStart(ctx) {
console.log('onBuildStart');
if (!isInitialBuild && !skipRebuildLogs) {
outputInfo(LOG_REBUILDING);
console.time(LOG_REBUILT);
Expand All @@ -270,6 +275,7 @@ export async function runClassicCompilerDev({
},
onBuildManifest: liveReload?.onBuildManifest,
async onBuildFinish(context, duration, succeeded) {
console.log('onBuildFinish', new Error());
if (isInitialBuild) {
await copyFilesPromise;
initialBuildDurationMs = Date.now() - initialBuildStartTimeMs;
Expand All @@ -280,6 +286,8 @@ export async function runClassicCompilerDev({
if (!miniOxygen) console.log(''); // New line
}

console.log('serverBundleExists', await serverBundleExists());

if (!miniOxygen && !(await serverBundleExists())) {
return renderFatalError({
name: 'BuildError',
Expand Down
34 changes: 20 additions & 14 deletions packages/cli/src/lib/codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export function spawnCodegenProcess({

child.stderr.on('data', (data) => {
const dataString: string =
typeof data === 'string' ? data : data?.toString?.('utf8') ?? '';
typeof data === 'string' ? data : (data?.toString?.('utf8') ?? '');

if (!dataString) return;

Expand Down Expand Up @@ -204,15 +204,18 @@ async function generateTypes({

await generate(codegenContext, true);

return Object.entries(codegenConfig.generates).reduce((acc, [key, value]) => {
if ('documents' in value) {
acc[key] = (
Array.isArray(value.documents) ? value.documents : [value.documents]
).filter((document) => typeof document === 'string') as string[];
}
return Object.entries(codegenConfig.generates).reduce(
(acc, [key, value]) => {
if ('documents' in value) {
acc[key] = (
Array.isArray(value.documents) ? value.documents : [value.documents]
).filter((document) => typeof document === 'string') as string[];
}

return acc;
}, {} as Record<string, string[]>);
return acc;
},
{} as Record<string, string[]>,
);
}

export async function generateDefaultConfig(
Expand Down Expand Up @@ -353,10 +356,13 @@ function getCodegenFromGraphQLConfig(

return Object.entries(
project.extensions.codegen.generates as CodegenConfig['generates'][string],
).reduce((acc, [key, value]) => {
acc[key] = {...project, ...(Array.isArray(value) ? value[0] : value)};
return acc;
}, {} as CodegenConfig['generates']);
).reduce(
(acc, [key, value]) => {
acc[key] = {...project, ...(Array.isArray(value) ? value[0] : value)};
return acc;
},
{} as CodegenConfig['generates'],
);
}

/**
Expand Down Expand Up @@ -409,7 +415,7 @@ async function addHooksToHydrogenOptions(

hydrogenOptions.hooks = {
beforeOneFileWrite: (file: string, content: string) =>
formatCode(content, formatConfig, file),
formatCode(content, formatConfig),
...hydrogenOptions.hooks,
};
}
Expand Down
38 changes: 24 additions & 14 deletions packages/cli/src/lib/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export async function replaceFileContent(
if (typeof content !== 'string') return;

if (formatConfig) {
content = await formatCode(content, formatConfig, filepath);
content = await formatCode(content, formatConfig);
}

return writeFile(filepath, content);
Expand Down Expand Up @@ -94,12 +94,15 @@ export async function mergePackageJson(
onResult?: (pkgJson: PackageJson) => PackageJson;
},
) {
console.log('mergePackageJson 1');
const targetPkgJson: PackageJson = await readAndParsePackageJson(
joinPath(targetDir, 'package.json'),
);
console.log('mergePackageJson 2');
const sourcePkgJson: PackageJson = await readAndParsePackageJson(
joinPath(sourceDir, 'package.json'),
);
console.log('mergePackageJson 3');

const ignoredKeys = new Set(['comment', ...(options?.ignoredKeys ?? [])]);

Expand All @@ -117,11 +120,12 @@ export async function mergePackageJson(
Array.isArray(sourceValue) && Array.isArray(targetValue)
? [...targetValue, ...sourceValue]
: typeof sourceValue === 'object' && typeof targetValue === 'object'
? {...targetValue, ...sourceValue}
: sourceValue;
? {...targetValue, ...sourceValue}
: sourceValue;

targetPkgJson[key] = newValue as any;
}
console.log('mergePackageJson 4');

const remixVersion = Object.entries(targetPkgJson.dependencies || {}).find(
([dep]) => dep.startsWith('@remix-run/'),
Expand All @@ -138,27 +142,33 @@ export async function mergePackageJson(
]),
]
.sort()
.reduce((acc, dep) => {
let version = (sourcePkgJson[key]?.[dep] ??
targetPkgJson[key]?.[dep])!;

if (dep.startsWith('@remix-run/') && remixVersion) {
version = remixVersion;
}

acc[dep] = version;
return acc;
}, {} as Record<string, string>);
.reduce(
(acc, dep) => {
let version = (sourcePkgJson[key]?.[dep] ??
targetPkgJson[key]?.[dep])!;

if (dep.startsWith('@remix-run/') && remixVersion) {
version = remixVersion;
}

acc[dep] = version;
return acc;
},
{} as Record<string, string>,
);
}
}
console.log('mergePackageJson 5');

await writePackageJSON(
targetDir,
options?.onResult?.(targetPkgJson) ?? targetPkgJson,
);
console.log('mergePackageJson 6');
}

export async function mergeTsConfig(sourceDir: string, targetDir: string) {
console.log('mergeTsConfig');
const sourceTsConfig = await readFile(joinPath(sourceDir, 'tsconfig.json'));
const sourceTsTypes = sourceTsConfig.match(/"types": \[(.*?)\]/)?.[1];

Expand Down
18 changes: 11 additions & 7 deletions packages/cli/src/lib/format-code.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import type {Options as FormatOptions} from 'prettier';
import {extname} from '@shopify/cli-kit/node/path';
import * as prettier from 'prettier';
import * as FS from 'fs/promises';
import * as Path from 'path';

export type {FormatOptions};

Expand All @@ -12,9 +14,14 @@ const DEFAULT_PRETTIER_CONFIG: FormatOptions = {
};

export async function getCodeFormatOptions(filePath = process.cwd()) {
// Appears the semantics of `resolvedFonfige` have changed:
// https://github.com/prettier/prettier/issues/16344
const pathToUse = (await FS.lstat(filePath)).isFile()
? filePath
: Path.resolve(filePath, 'prettier.file');
try {
// Try to read a prettier config file from the project.
return (await prettier.resolveConfig(filePath)) || DEFAULT_PRETTIER_CONFIG;
return (await prettier.resolveConfig(pathToUse)) || DEFAULT_PRETTIER_CONFIG;
} catch {
return DEFAULT_PRETTIER_CONFIG;
}
Expand All @@ -23,15 +30,12 @@ export async function getCodeFormatOptions(filePath = process.cwd()) {
export async function formatCode(
content: string,
config: FormatOptions = DEFAULT_PRETTIER_CONFIG,
filePath = '',
) {
const ext = extname(filePath);

return prettier.format(content, {
// Specify the TypeScript parser for ts/tsx files. Otherwise
// we need to use the babel parser because the default parser
// Otherwise prettier will print a warning.
parser: ext === '.tsx' || ext === '.ts' ? 'typescript' : 'babel',
// we need to use the babel parser instead of the default parser,
// because prettier will print a warning.
parser: 'typescript',
...config,
});
}
Loading

0 comments on commit 345846b

Please sign in to comment.