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: use relative path to require css modules #4

Merged
merged 8 commits into from
Dec 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
13 changes: 12 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,13 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
os: [windows-latest, ubuntu-latest, macos-latest]
node: [16]
steps:
- name: Prepare git on Windows
if: matrix.os == 'windows-latest'
run: git config --global core.autocrlf false

- uses: actions/checkout@v3
- uses: pnpm/[email protected]
with:
Expand Down Expand Up @@ -43,4 +47,11 @@ jobs:

- name: Run tests
run: pnpm run test

- name: Upload test results
if: ${{ failure() }}
uses: actions/upload-artifact@v3
with:
name: playwright-report
path: tests/example/apps/nextjs/test-results

5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
node_modules/
.next/
lib/

.DS_Store
test-results/
.DS_Store
tests/example/apps/nextjs/.vscode/settings.json
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "next-with-linaria",
"version": "0.3.0",
"version": "0.3.1-canary.0",
"description": "Linaria support for Next.js 13 app directory feature",
"main": "lib/webpackConfig.js",
"scripts": {
Expand Down
23 changes: 13 additions & 10 deletions src/loaders/transformLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,20 +115,23 @@ const transformLoader: LoaderType = function (content, inputSourceMap) {
const fileDir = path.dirname(this.resourcePath);
const isGlobalStyle = filename.endsWith(LINARIA_GLOBAL_EXTENSION);

const outputFileName = path.join(
fileDir,
`${filename}${isGlobalStyle ? '' : LINARIA_MODULE_EXTENSION}.css`,
);
const cssModuleName = `${filename}${
isGlobalStyle ? '' : LINARIA_MODULE_EXTENSION
}.css`;

moduleStore.addModule(outputFileName, cssText);
moduleStore.addModuleDependencies(
outputFileName,
this.getDependencies(),
);
const fullPathToModule = path.join(fileDir, cssModuleName);

await Promise.all([
moduleStore.addModule(fullPathToModule, cssText),
moduleStore.addModuleDependencies(
fullPathToModule,
this.getDependencies(),
),
]);

this.callback(
null,
`${result.code}\n\nrequire("${outputFileName}");`,
`${result.code}\n\nrequire("./${cssModuleName}");`,
result.sourceMap ?? undefined,
);
} catch (err) {
Expand Down
4 changes: 0 additions & 4 deletions tests/example/apps/nextjs/.vscode/settings.json

This file was deleted.

25 changes: 13 additions & 12 deletions tests/example/apps/nextjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,26 @@
"build": "next build",
"start": "next start",
"lint": "next lint",
"test": "TARGET=prod playwright test && TARGET=dev playwright test"
"test": "cross-env TARGET=prod playwright test && cross-env TARGET=dev playwright test"
},
"dependencies": {
"@linaria/core": "4.2.2",
"@linaria/react": "4.3.0",
"next": "13.0.2",
"@linaria/core": "4.2.4",
"@linaria/react": "4.3.2",
"next": "13.0.6",
"react": "18.2.0",
"react-dom": "18.2.0",
"ui-kit": "workspace:1.0.0"
},
"devDependencies": {
"@linaria/babel-preset": "4.3.0",
"@playwright/test": "1.27.1",
"@types/node": "18.11.7",
"@types/react": "18.0.24",
"@types/react-dom": "18.0.8",
"eslint": "8.26.0",
"eslint-config-next": "13.0.2",
"@linaria/babel-preset": "4.3.2",
"@playwright/test": "1.28.1",
"@types/node": "18.11.14",
"@types/react": "18.0.26",
"@types/react-dom": "18.0.9",
"cross-env": "^7.0.3",
"eslint": "8.29.0",
"eslint-config-next": "13.0.6",
"nodemon": "2.0.20",
"typescript": "4.8.4"
"typescript": "4.9.4"
}
}
2 changes: 2 additions & 0 deletions tests/example/apps/nextjs/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@ const config: PlaywrightTestConfig = {
outputDir: path.join(__dirname, 'test-results'),
testDir: path.join(__dirname, 'e2e'),
workers: isCI ? 2 : undefined,
reporter: process.env.CI ? 'github' : 'list',
webServer: {
command: webServer.command,
port: port,
reuseExistingServer: !isCI,
},
use: {
trace: 'on-first-retry',
screenshot: 'only-on-failure',
},
projects: [
{
Expand Down
4 changes: 2 additions & 2 deletions tests/example/packages/ui-kit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"author": "",
"license": "ISC",
"dependencies": {
"@linaria/core": "^4.2.2",
"@linaria/react": "^4.3.0"
"@linaria/core": "^4.2.4",
"@linaria/react": "^4.3.2"
},
"devDependencies": {
"react": "18.2.0"
Expand Down
Loading