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

[system] Add missing main entry for styleFunctionSx #25885

Merged
merged 2 commits into from
Apr 23, 2021
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
6 changes: 3 additions & 3 deletions scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ async function run(argv) {
.filter((file) => {
return path.basename(file, path.extname(file)) !== 'index';
});
const topLevelPathImportsArePackages = topLevelNonIndexFiles.length === 0;
const topLevelPathImportsCanBePackages = topLevelNonIndexFiles.length === 0;

const outDir = path.resolve(
relativeOutDir,
Expand All @@ -60,9 +60,9 @@ async function run(argv) {
// Different extensions are not viable yet since they require additional bundler config for users and additional transpilation steps in our repo.
// Switch to `exports` field in v6.
{
node: topLevelPathImportsArePackages ? './node' : './',
node: topLevelPathImportsCanBePackages ? './node' : './',
modern: './modern',
stable: topLevelPathImportsArePackages ? './' : './esm',
stable: topLevelPathImportsCanBePackages ? './' : './esm',
legacy: './legacy',
}[bundle],
);
Expand Down
42 changes: 31 additions & 11 deletions scripts/copy-files.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,31 +21,51 @@ async function includeFileInBuild(file) {
*
* It also tests that an this import can be used in TypeScript by checking
* if an index.d.ts is present at that path.
* @param {string} rootDir
* @param {object} param0
* @param {string} param0.from
* @param {string} param0.to
*/
async function createModulePackages({ from, to }) {
const directoryPackages = glob.sync('*/index.{js,ts,tsx}', { cwd: from }).map(path.dirname);

await Promise.all(
directoryPackages.map(async (directoryPackage) => {
const packageJsonPath = path.join(to, directoryPackage, 'package.json');
const topLevelPathImportsAreCommonJSModules = await fse.pathExists(
path.resolve(path.dirname(packageJsonPath), '../esm'),
);

const packageJson = {
sideEffects: false,
module: './index.js',
main: path.posix.join('../node', directoryPackage, 'index.js'),
module: topLevelPathImportsAreCommonJSModules
? path.posix.join('../esm', directoryPackage, 'index.js')
: './index.js',
main: topLevelPathImportsAreCommonJSModules
? './index.js'
: path.posix.join('../node', directoryPackage, 'index.js'),
types: './index.d.ts',
};

const packageJsonPath = path.join(to, directoryPackage, 'package.json');

const typingsPath = path.join(to, directoryPackage, 'index.d.ts');

const [typingsExist] = await Promise.all([
fse.pathExists(typingsPath),
const [typingsEntryExist, moduleEntryExists, mainEntryExists] = await Promise.all([
fse.pathExists(path.resolve(path.dirname(packageJsonPath), packageJson.types)),
fse.pathExists(path.resolve(path.dirname(packageJsonPath), packageJson.module)),
fse.pathExists(path.resolve(path.dirname(packageJsonPath), packageJson.main)),
fse.writeFile(packageJsonPath, JSON.stringify(packageJson, null, 2)),
]);

if (!typingsExist) {
throw new Error(`index.d.ts for ${directoryPackage} is missing. Path: '${typingsPath}'`);
const manifestErrorMessages = [];
if (!typingsEntryExist) {
manifestErrorMessages.push(`'types' entry '${packageJson.types}' does not exist`);
}
if (!moduleEntryExists) {
manifestErrorMessages.push(`'module' entry '${packageJson.module}' does not exist`);
}
if (!mainEntryExists) {
manifestErrorMessages.push(`'main' entry '${packageJson.main}' does not exist`);
}
if (manifestErrorMessages.length > 0) {
// TODO: AggregateError
throw new Error(`${packageJsonPath}:\n${manifestErrorMessages.join('\n')}`);
}

return packageJsonPath;
Expand Down