-
Notifications
You must be signed in to change notification settings - Fork 325
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into fd-fix-public-assets
- Loading branch information
Showing
17 changed files
with
173 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
name: Publish to Stackblitz | ||
|
||
on: | ||
release: | ||
types: [published] | ||
|
||
jobs: | ||
publish: | ||
runs-on: ubuntu-latest | ||
name: Publish latest release to Stackblitz | ||
steps: | ||
- name: Checkout the code | ||
uses: actions/checkout@v2 | ||
- name: Rename gitignore | ||
run: | | ||
mv packages/dev/_gitignore packages/dev/.gitignore | ||
- name: Push to stackblitz branch | ||
uses: EndBug/[email protected] | ||
with: | ||
push: 'origin stackblitz --force' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"installDependencies": true, | ||
"startCommand": "npm run dev" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
...ork/plugins/__tests__/__snapshots__/vite-plugin-react-server-components-shim.spec.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`transforms client-imports 1`] = ` | ||
"// Transform relative paths to absolute in order | ||
// to match component IDs from ClientMarker. | ||
function normalizeComponentPaths( | ||
componentObject: Record<string, undefined | (() => any)>, | ||
prefix: string | ||
) { | ||
return Object.entries(componentObject).reduce((acc, [key, value]) => { | ||
acc[prefix + key.replace(/\\\\.\\\\.\\\\//gm, '')] = value; | ||
return acc; | ||
}, {} as typeof componentObject); | ||
} | ||
// These strings are replaced in a plugin with real globs | ||
// and paths that depend on the user project structure. | ||
const allClientComponents = { | ||
...normalizeComponentPaths( | ||
// @ts-ignore | ||
import.meta.glob('../../components/**/*.client.js'), | ||
\`@shopify/\` | ||
), | ||
...normalizeComponentPaths( | ||
// @ts-ignore | ||
import.meta.glob('../../../src/**/*.client.[jt]sx'), | ||
\`./\` | ||
), | ||
}; | ||
export default function importClientComponent(moduleId: string) { | ||
const modImport = allClientComponents[moduleId]; | ||
if (!modImport) { | ||
throw new Error(\`Could not find client component \${moduleId}\`); | ||
} | ||
return modImport(); | ||
} | ||
" | ||
`; |
52 changes: 52 additions & 0 deletions
52
...hydrogen/src/framework/plugins/__tests__/vite-plugin-react-server-components-shim.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import middleware from '../vite-plugin-react-server-components-shim'; | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
import {resolve} from '../resolver'; | ||
|
||
jest.mock('../resolver'); | ||
|
||
(resolve as any).mockImplementation(() => '@shopify/hydrogen'); | ||
|
||
let m: any; | ||
|
||
beforeEach(() => { | ||
m = middleware(); | ||
m.configResolved({ | ||
root: '.', | ||
}); | ||
}); | ||
|
||
it('only transforms client-imports', function () { | ||
expect(m.transform('', '')).toBe(undefined); | ||
}); | ||
|
||
it('transforms client-imports', function () { | ||
const code = fs.readFileSync( | ||
path.resolve(__dirname, '../../Hydration/client-imports.ts'), | ||
'utf8' | ||
); | ||
const result = m.transform(code, '/Hydration/client-imports'); | ||
|
||
expect(result).toMatchSnapshot(); | ||
}); | ||
|
||
it('throws an error when non-Server components load Server components', async function () { | ||
await expect(m.resolveId('.server.tsx', '.client.tsx')).rejects.toThrow(); | ||
|
||
await expect(m.resolveId('.server.jsx', '.client.jsx')).rejects.toThrow(); | ||
}); | ||
|
||
it('passes when server components import client components', async function () { | ||
m.resolveId('.client.tsx', '.server.tsx'); | ||
m.resolveId('.client.jsx', '.server.jsx'); | ||
}); | ||
|
||
it('throws an error when client components load hydrogen from the server-only entrypoint', async function () { | ||
await expect( | ||
m.resolveId('@shopify/hydrogen', '.client.tsx') | ||
).rejects.toThrow(); | ||
|
||
await expect( | ||
m.resolveId('@shopify/hydrogen', '.client.jsx') | ||
).rejects.toThrow(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export function resolve(path: string) { | ||
return require.resolve(path); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters