-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature: allow defining module scripts through project config decoupl…
…ed from blocks (#388) Co-authored-by: Nícholas André <[email protected]>
- Loading branch information
1 parent
1693913
commit 20d2e65
Showing
13 changed files
with
109 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"10up-toolkit": patch | ||
"tenup-theme": patch | ||
--- | ||
|
||
Feature: allow defining module script entrypoints via `moduleEntry` key in `package.json` decoupled from blocks |
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 @@ | ||
./dist |
1 change: 1 addition & 0 deletions
1
packages/toolkit/__tests__/build-project-modules/__fixtures__/assets/css/admin-styles.css
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 @@ | ||
.admin-class { color: blue; } |
1 change: 1 addition & 0 deletions
1
packages/toolkit/__tests__/build-project-modules/__fixtures__/assets/css/frontend.css
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 @@ | ||
.test { color: red; } |
3 changes: 3 additions & 0 deletions
3
packages/toolkit/__tests__/build-project-modules/__fixtures__/assets/js/admin.js
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 @@ | ||
import '../css/admin-styles.css'; | ||
|
||
export const admin = () => {}; |
12 changes: 12 additions & 0 deletions
12
packages/toolkit/__tests__/build-project-modules/package.json
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,12 @@ | ||
{ | ||
"name": "test-build-project", | ||
"10up-toolkit": { | ||
"useBlockAssets": false, | ||
"entry": { | ||
"frontend-css": "./__fixtures__/assets/css/frontend.css" | ||
}, | ||
"moduleEntry": { | ||
"admin": "./__fixtures__/assets/js/admin.js" | ||
} | ||
} | ||
} |
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,35 @@ | ||
/* eslint-disable import/no-extraneous-dependencies */ | ||
import spawn from 'cross-spawn'; | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
|
||
describe('build a project with moduleEntry', () => { | ||
it('builds and compiles js and css', async () => { | ||
spawn.sync('node', ['../../scripts/build', '--block-modules'], { | ||
cwd: __dirname, | ||
}); | ||
|
||
const adminJsPath = path.join(__dirname, 'dist', 'js', 'admin.js'); | ||
|
||
expect(fs.existsSync(adminJsPath)).toBeTruthy(); | ||
expect(fs.existsSync(path.join(__dirname, 'dist', 'css', 'frontend-css.css'))).toBeTruthy(); | ||
expect( | ||
fs.existsSync(path.join(__dirname, 'dist', 'css', 'frontend-css.asset.php')), | ||
).toBeTruthy(); | ||
|
||
// ensure admin is a module | ||
const adminJs = fs.readFileSync(adminJsPath).toString(); | ||
expect(adminJs).toMatch(/export {.*};/); | ||
}); | ||
|
||
it('extracts css imported in js files', () => { | ||
spawn.sync('node', ['../../scripts/build', '--block-modules'], { | ||
cwd: __dirname, | ||
}); | ||
// chunk name for css imported in js matches the js entry point | ||
expect(fs.existsSync(path.join(__dirname, 'dist', 'css', 'admin.css'))).toBeTruthy(); | ||
|
||
// this should not exist since it is not an entry point on its own | ||
expect(fs.existsSync(path.join(__dirname, 'dist', 'css', 'admin-styles.css'))).toBeFalsy(); | ||
}); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { store } from '@wordpress/interactivity'; | ||
|
||
const { state } = store('frontend', { | ||
state: { | ||
isExpanded: false, | ||
}, | ||
actions: { | ||
toggleExpanded() { | ||
state.isExpanded = !state.isExpanded; | ||
}, | ||
}, | ||
}); |
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