Skip to content

Commit

Permalink
DataViews: WP Specific build (#66825)
Browse files Browse the repository at this point in the history
Co-authored-by: youknowriad <[email protected]>
Co-authored-by: sirreal <[email protected]>
Co-authored-by: luisherranz <[email protected]>
Co-authored-by: jsnajdr <[email protected]>
Co-authored-by: louwie17 <[email protected]>
Co-authored-by: ntsekouras <[email protected]>
Co-authored-by: Tropicalista <[email protected]>
Co-authored-by: mirka <[email protected]>
Co-authored-by: manzoorwanijk <[email protected]>
  • Loading branch information
10 people authored Nov 27, 2024
1 parent 738d5bf commit 14adfdb
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ build
build-module
build-style
build-types
build-wp
node_modules
gutenberg.zip
coverage
Expand Down
1 change: 1 addition & 0 deletions package-lock.json

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

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
"cssnano": "6.0.1",
"deep-freeze": "0.0.1",
"equivalent-key-map": "0.2.2",
"esbuild": "0.18.20",
"escape-html": "1.0.3",
"eslint-import-resolver-node": "0.3.4",
"eslint-plugin-eslint-comments": "3.1.2",
Expand Down Expand Up @@ -177,9 +178,10 @@
"build:package-types": "node ./bin/packages/validate-typescript-version.js && ( tsc --build || ( echo 'tsc failed. Try cleaning up first: `npm run clean:package-types`'; exit 1 ) ) && node ./bin/packages/check-build-type-declaration-files.js",
"prebuild:packages": "npm run clean:packages && npm run --if-present --workspaces build",
"build:packages": "npm run --silent build:package-types && node ./bin/packages/build.js",
"postbuild:packages": " npm run --if-present --workspaces build:wp",
"build:plugin-zip": "bash ./bin/build-plugin-zip.sh",
"clean:package-types": "tsc --build --clean && rimraf \"./packages/*/build-types\"",
"clean:packages": "rimraf \"./packages/*/@(build|build-module|build-style)\"",
"clean:packages": "rimraf \"./packages/*/@(build|build-module|build-wp|build-style)\"",
"component-usage-stats": "node ./node_modules/react-scanner/bin/react-scanner -c ./react-scanner.config.js",
"dev": "cross-env NODE_ENV=development npm run build:packages && concurrently \"wp-scripts start\" \"npm run dev:packages\"",
"dev:packages": "cross-env NODE_ENV=development concurrently \"node ./bin/packages/watch.js\" \"tsc --build --watch\"",
Expand Down
2 changes: 2 additions & 0 deletions packages/dataviews/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ npm install @wordpress/dataviews --save

<div class="callout callout-info">At <a href="https://wordpress.github.io/gutenberg/">WordPress Gutenberg's Storybook</a> there's and <a href="https://wordpress.github.io/gutenberg/?path=/docs/dataviews-dataviews--docs">example implementation of the Dataviews component</a>.</div>

**Important note** If you're trying to use the `DataViews` component in a WordPress plugin or theme and you're building your scripts using the `@wordpress/scripts` package, you need to import the components from `@wordpress/dataviews/wp` instead of `@wordpress/dataviews`.

### Usage

The `DataViews` component receives data and some other configuration to render the dataset. It'll call the `onChangeView` callback every time the user has interacted with the dataset in some way (sorted, filtered, changed layout, etc.):
Expand Down
33 changes: 33 additions & 0 deletions packages/dataviews/build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* External dependencies
*/
// eslint-disable-next-line import/no-extraneous-dependencies
const esbuild = require( 'esbuild' );

const wpExternals = {
name: 'wordpress-externals',
setup( build ) {
build.onResolve( { filter: /^@wordpress\// }, () => {
// Bundle wordpress packages
return { external: false };
} );
build.onResolve( { filter: /^\.[\.\/]/ }, () => {
// Bundle relative paths
return { external: false };
} );
build.onResolve( { filter: /.+/ }, ( args ) => {
// Mark everything else as external
return { path: args.path, external: true };
} );
},
};

esbuild.build( {
entryPoints: [ 'src/index.ts' ],
bundle: true,
outdir: 'build-wp',
plugins: [ wpExternals ],
jsx: 'automatic',
logLevel: 'info',
format: 'esm',
} );
17 changes: 17 additions & 0 deletions packages/dataviews/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,20 @@
},
"main": "build/index.js",
"module": "build-module/index.js",
"exports": {
".": {
"types": "./build-types/index.d.ts",
"import": "./build-module/index.js"
},
"./wp": {
"types": "./build-types/index.d.ts",
"default": "./build-wp/index.js"
},
"./package.json": {
"default": "./package.json"
},
"./build-style/": "./build-style/"
},
"react-native": "src/index",
"wpScript": true,
"types": "build-types",
Expand All @@ -48,5 +62,8 @@
},
"publishConfig": {
"access": "public"
},
"scripts": {
"build:wp": "node build"
}
}
1 change: 1 addition & 0 deletions packages/dependency-extraction-webpack-plugin/lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const WORDPRESS_NAMESPACE = '@wordpress/';
// !!
const BUNDLED_PACKAGES = [
'@wordpress/dataviews',
'@wordpress/dataviews/wp',
'@wordpress/icons',
'@wordpress/interface',
'@wordpress/sync',
Expand Down
1 change: 1 addition & 0 deletions tools/webpack/packages.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const WORDPRESS_NAMESPACE = '@wordpress/';
// !!
const BUNDLED_PACKAGES = [
'@wordpress/dataviews',
'@wordpress/dataviews/wp',
'@wordpress/icons',
'@wordpress/interface',
'@wordpress/sync',
Expand Down

1 comment on commit 14adfdb

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in 14adfdb.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/12048406912
📝 Reported issues:

Please sign in to comment.