docusaurus/packages/docusaurus-theme-common/removeThemeInternalReexport.mjs
Sébastien Lorber 9473508c33
refactor(theme-common): split package into public/internal API entrypoints (#7660)
* add theme-common/internal export

* Split @docusaurus/theme-common into public/internal apis

* fixes

* public <-> private

* public <-> private

* public <-> private

* fix

* add "removeThemeInternalReexport" CI script

* :s windows CI check not working: not that useful

* remove bad import

* refactors

* reorder

* make useBackToTopButton internal

Co-authored-by: Joshua Chen <sidachen2003@gmail.com>
2022-06-24 11:21:27 +02:00

32 lines
948 B
JavaScript

/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import fs from 'fs-extra';
// See comment in src/internal.ts
// This script should be run by CI tests to remove:
// export * from './index'
const filePath = 'lib/internal.js';
const lineToRemove = "export * from './index';\n";
if (!(await fs.pathExists(filePath))) {
throw new Error(`internal entrypoint file not found at ${filePath}`);
}
const fileContent = await fs.readFile(filePath, 'utf8');
const fileContentUpdated = fileContent.replaceAll(lineToRemove, '');
// Ensure the script correctly removes the re-export
if (fileContent === fileContentUpdated) {
throw new Error(
'Unexpected: internal re-export has not been replaced.\nMake sure this script works, and is only run once.',
);
}
await fs.writeFile(filePath, fileContentUpdated);