Skip to content

Commit

Permalink
General fixes before releasing (#1974)
Browse files Browse the repository at this point in the history
* Add missing dependency

* Fix transpilation of eslintrc file

* Fix vite scaffold asset

* Fix upgrade notice for next version

* Avoid initial reload in Vite

* Fix style after commit from GH

* Hoist known dependencies in PNPM to ensure Vite can optimize them

* New line

* Longer timeout for mini-oxygen tests
  • Loading branch information
frandiox authored Apr 11, 2024
1 parent f0c58e0 commit 052eb14
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 15 deletions.
4 changes: 3 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion packages/cli/src/commands/hydrogen/upgrade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -999,7 +999,8 @@ export async function displayDevUpgradeNotice({

const isPrerelease = semver.prerelease(currentVersion);

if (isPrerelease) {
if (isPrerelease || /^[a-z]+$/i.test(currentVersion)) {
// Skip prereleases or versions like 'next' or 'latest'
return;
}

Expand Down
9 changes: 8 additions & 1 deletion packages/cli/src/lib/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,14 @@ export async function replaceFileContent(
return writeFile(filepath, content);
}

const DEFAULT_EXTENSIONS = ['tsx', 'ts', 'jsx', 'js', 'mjs', 'cjs'] as const;
const DEFAULT_EXTENSIONS = [
'tsx' as const,
'ts' as const,
'jsx' as const,
'js' as const,
'mjs' as const,
'cjs' as const,
];

export async function findFileWithExtension(
directory: string,
Expand Down
14 changes: 10 additions & 4 deletions packages/cli/src/lib/transpile/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {outputDebug} from '@shopify/cli-kit/node/output';
import {joinPath} from '@shopify/cli-kit/node/path';
import {formatCode, getCodeFormatOptions} from '../format-code.js';
import {transpileFile} from './file.js';
import {findFileWithExtension} from '../file.js';

const DEFAULT_JS_CONFIG: Omit<CompilerOptions, 'jsx'> = {
checkJs: false,
Expand Down Expand Up @@ -157,15 +158,20 @@ export async function transpileProject(projectDir: string, keepTypes = true) {

// Remove TS from ESLint
try {
const eslintrcPath = joinPath(projectDir, '.eslintrc.js');
let eslintrc = await readFile(eslintrcPath);
const {filepath = joinPath(projectDir, '.eslintrc.cjs')} =
await findFileWithExtension(projectDir, '.eslintrc', ['cjs', 'js']);

let eslintrc = await readFile(filepath);

if (!keepTypes) {
eslintrc = eslintrc.replace(/\/\*\*[\s*]+@type.+\s+\*\/\s?/gim, '');
}

eslintrc = eslintrc
.replace(/\/\*\*[\s*]+@type.+\s+\*\/\s?/gim, '')
.replace(/\s*,?\s*['"`]plugin:hydrogen\/typescript['"`]/gim, '')
.replace(/\s+['"`]@typescript-eslint\/.+,/gim, '');

await writeFile(eslintrcPath, eslintrc);
await writeFile(filepath, await formatCode(eslintrc, formatConfig));
} catch (error) {
outputDebug(
'Could not remove TS rules from .eslintrc:\n' + (error as Error).stack,
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/setup-assets/vite/package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"type": "module",
"scripts": {
"build": "shopify hydrogen build-vite --codegen",
"dev": "shopify hydrogen dev-vite --codegen"
"build": "shopify hydrogen build --codegen",
"dev": "shopify hydrogen dev --codegen"
},
"dependencies": {
"isbot": "^3.8.0"
Expand Down
5 changes: 1 addition & 4 deletions packages/hydrogen-react/src/storefront-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,7 @@ export function createStorefrontClient({
}: StorefrontClientProps): StorefrontClientReturn {
if (!storeDomain) {
storeDomain = MOCK_SHOP_DOMAIN;
warnOnce(
`storeDomain missing, defaulting to ${MOCK_SHOP_DOMAIN}`,
'info',
);
warnOnce(`storeDomain missing, defaulting to ${MOCK_SHOP_DOMAIN}`, 'info');
}

if (storefrontApiVersion !== SFAPI_VERSION) {
Expand Down
3 changes: 2 additions & 1 deletion packages/hydrogen/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@
"@shopify/hydrogen-react": "2024.4.0",
"content-security-policy-builder": "^2.1.1",
"type-fest": "^4.5.0",
"source-map-support": "^0.5.21"
"source-map-support": "^0.5.21",
"use-resize-observer": "^9.1.0"
},
"devDependencies": {
"@remix-run/react": "^2.8.0",
Expand Down
5 changes: 5 additions & 0 deletions packages/hydrogen/src/vite/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ export function hydrogen(pluginOptions: HydrogenPluginOptions = {}): Plugin[] {
],
},
},
// Vite performs an initial reload after optimizing these dependencies.
// Do it early to avoid the initial reload:
optimizeDeps: {
include: ['@shopify/hydrogen'],
},
};
},
api: {
Expand Down
2 changes: 1 addition & 1 deletion packages/mini-oxygen/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"dev": "tsup --watch",
"typecheck": "tsc --noEmit",
"prepack": "npm run build",
"test": "NODE_OPTIONS=--experimental-vm-modules vitest run"
"test": "NODE_OPTIONS=--experimental-vm-modules vitest run --test-timeout=20000"
},
"files": [
"dist"
Expand Down
5 changes: 5 additions & 0 deletions templates/skeleton/.npmrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
@shopify:registry=https://registry.npmjs.com
progress=false

# Ensure Vite can optimize these deps in PNPM
public-hoist-pattern[]=cookie
public-hoist-pattern[]=set-cookie-parser
public-hoist-pattern[]=content-security-policy-builder

0 comments on commit 052eb14

Please sign in to comment.