Skip to content
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
34 changes: 0 additions & 34 deletions packages/private-apis/src/implementation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,6 @@ const CORE_MODULES_USING_PRIVATE_APIS = [
'@wordpress/global-styles-ui',
];

/**
* A list of core modules that already opted-in to
* the privateApis package.
*/
const registeredPrivateApis: Array< string > = [];

/*
* Warning for theme and plugin developers.
*
Expand All @@ -66,9 +60,6 @@ const registeredPrivateApis: Array< string > = [];
const requiredConsent =
'I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.';

// The safety measure is meant for WordPress core where IS_WORDPRESS_CORE is set to true.
const allowReRegistration = globalThis.IS_WORDPRESS_CORE ? false : true;

/**
* Called by a @wordpress package wishing to opt-in to accessing or exposing
* private private APIs.
Expand All @@ -90,21 +81,6 @@ export const __dangerousOptInToUnstableAPIsOnlyForCoreModules = (
'your product will inevitably break on one of the next WordPress releases.'
);
}
if (
! allowReRegistration &&
registeredPrivateApis.includes( moduleName )
) {
// This check doesn't play well with Story Books / Hot Module Reloading
// and isn't included in the Gutenberg plugin. It only matters in the
// WordPress core release.
throw new Error(
`You tried to opt-in to unstable APIs as module "${ moduleName }" which is already registered. ` +
'This feature is only for JavaScript modules shipped with WordPress core. ' +
'Please do not use it in plugins and themes as the unstable APIs will be removed ' +
'without a warning. If you ignore this error and depend on unstable features, ' +
'your product will inevitably break on one of the next WordPress releases.'
);
}
if ( consent !== requiredConsent ) {
throw new Error(
`You tried to opt-in to unstable APIs without confirming you know the consequences. ` +
Expand All @@ -114,7 +90,6 @@ export const __dangerousOptInToUnstableAPIsOnlyForCoreModules = (
'your product will inevitably break on the next WordPress release.'
);
}
registeredPrivateApis.push( moduleName );

return {
lock,
Expand Down Expand Up @@ -225,12 +200,3 @@ export function resetAllowedCoreModules() {
CORE_MODULES_USING_PRIVATE_APIS.pop();
}
}
/**
* Private function to allow the unit tests to reset
* the list of registered private apis.
*/
export function resetRegisteredPrivateApis() {
while ( registeredPrivateApis.length ) {
registeredPrivateApis.pop();
}
}
20 changes: 2 additions & 18 deletions packages/private-apis/src/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,9 @@
* Internal dependencies
*/
import { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '../';
import {
resetRegisteredPrivateApis,
resetAllowedCoreModules,
allowCoreModule,
} from '../implementation';
import { resetAllowedCoreModules, allowCoreModule } from '../implementation';

beforeEach( () => {
resetRegisteredPrivateApis();
resetAllowedCoreModules();
allowCoreModule( '@privateApis/test' );
allowCoreModule( '@privateApis/test-consumer' );
Expand Down Expand Up @@ -37,18 +32,7 @@ describe( '__dangerousOptInToUnstableAPIsOnlyForCoreModules', () => {
/This feature is only for JavaScript modules shipped with WordPress core/
);
} );
it( 'Should not register the same module twice', () => {
expect( () => {
__dangerousOptInToUnstableAPIsOnlyForCoreModules(
requiredConsent,
'@privateApis/test'
);
__dangerousOptInToUnstableAPIsOnlyForCoreModules(
requiredConsent,
'@privateApis/test'
);
} ).toThrow( /is already registered/ );
} );

it( 'Should grant access to unstable APIs when passed both a consent string and a previously unregistered package name', () => {
const unstableAPIs = __dangerousOptInToUnstableAPIsOnlyForCoreModules(
requiredConsent,
Expand Down
Loading