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
2 changes: 1 addition & 1 deletion packages/react-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"build:umd": "rollup -c --environment IS_PRODUCTION",
"clean": "rimraf dist",
"generate": "node scripts/copyStyles.js",
"subpaths": "node scripts/copySubpaths.js"
"subpaths": "node scripts/createSubpaths.js"
},
"dependencies": {
"@patternfly/react-icons": "^5.0.0-alpha.6",
Expand Down
12 changes: 0 additions & 12 deletions packages/react-core/scripts/copySubpaths.js

This file was deleted.

32 changes: 32 additions & 0 deletions packages/react-core/scripts/createSubpaths.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* Re-export subpath modules into the package root directory for ease of access.
*/
const { readdirSync, readFileSync, writeFileSync, mkdirSync } = require('fs');
const { resolve, join } = require('path');

const isIndex = (fileName) => fileName.match(/^index\./);

const updatePaths = (filePath, subPathName) => {
const contents = readFileSync(filePath, { encoding: 'utf8' });
if (filePath.includes('.map')) {
return contents.replaceAll('../../../', `../`);
} else {
return contents.replaceAll('./', `../dist/esm/${subPathName}/`);
}
};

['next', 'deprecated', 'components', 'layouts', 'helpers'].forEach((subPathName) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you move this script into the root directory scripts folder, and then use a config file or pass in the parameters for the subpaths. This way we have it at one place instead of 2 copies. (e.g. yarn run createSubpaths.js --subpaths deperecated,components,layouts,helpers or create a subpath.json file that has the subpaths as json objects.
{ "subpaths": ["next", "deprecated", "components", "layouts", "helplers]

then in the script file just read them in by requiring the json file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I planned on cleaning it up a bit either as part of this PR or a followup, just wanted to get something up quick so that other people could test it and actually make sure that it works before I put more time into this approach.

Copy link
Contributor

Choose a reason for hiding this comment

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

That works just create a follow up issue. Thanks.

const distPath = resolve(__dirname, `../dist/esm/${subPathName}`);
const distFileNames = readdirSync(distPath);
const distIndexFileNames = distFileNames.filter((fileName) => isIndex(fileName));

const destinationDir = resolve(__dirname, `../${subPathName}`);
mkdirSync(destinationDir, { recursive: true });

distIndexFileNames.forEach((fileName) => {
const filePath = join(__dirname, '../dist/esm', subPathName, fileName);
const newFileContent = updatePaths(filePath, subPathName);
const fileDestination = join(destinationDir, fileName);
writeFileSync(fileDestination, newFileContent);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React from 'react';
import { render } from '@testing-library/react';

import { OptionsMenuItem } from '../../OptionsMenuItem';
import { DropdownArrowContext } from '../../../../../../components/Dropdown';
import { DropdownArrowContext } from '../../../../../components/Dropdown';

describe('OptionsMenuItem', () => {
it('should match snapshot', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/react-table/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"scripts": {
"build:umd": "rollup -c --environment IS_PRODUCTION",
"clean": "rimraf dist",
"subpaths": "node scripts/copySubpaths.js"
"subpaths": "node scripts/createSubpaths.js"
},
"dependencies": {
"@patternfly/react-core": "^5.0.0-alpha.42",
Expand Down
12 changes: 0 additions & 12 deletions packages/react-table/scripts/copySubpaths.js

This file was deleted.

32 changes: 32 additions & 0 deletions packages/react-table/scripts/createSubpaths.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* Re-export subpath modules into the package root directory for ease of access.
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we can keep this description so simple anymore since there is a lot more going on than a single copySync.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you have any recommendations?

It's doing a lot more operations, but it's still essentially completing the same goal of making the components available via importing from @patternfly/react-core/deprecated etc, it just does it via re-exporting rather than copying the actual component files.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't, and maybe it's just that we need better comments around the operations that are taking place below.

*/
const { readdirSync, readFileSync, writeFileSync, mkdirSync } = require('fs');
const { resolve, join } = require('path');

const isIndex = (fileName) => fileName.match(/^index\./);

const updatePaths = (filePath, subPathName) => {
const contents = readFileSync(filePath, { encoding: 'utf8' });
if (filePath.includes('.map')) {
return contents.replaceAll('../../../', `../`);
Copy link
Contributor

Choose a reason for hiding this comment

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

There are operations in this file that require explanation IMO. For instance, with this particular condition for .map filePaths, why do we need to do this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The sourcemap files point towards the source rather than pointing to dist like the exporting index files do, this conditional makes sure that we apply the proper update to both file types.

Also just generally I know a lot of the logic here isn't optimal. As I mentioned with Don's comment I plan to refine how exactly this is done, but wanted to validate that the fundamental change itself is good before investing more time in doing so.

Copy link
Contributor

Choose a reason for hiding this comment

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

What is happening and why isn't clear to me, so if I am to ignore the readability of this and expect the logic to change, validity at this point for me would be proof that this accomplishes what we want, and I'll pose that question to you. Meaning, have you tested this out with other packages locally?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In my local testing existing imports from /deprecated and /next seem to still work properly (as can be seen in the OptionsMenu and Select next docs pages in this PRs preview)

Without this change the deprecated wizard with drawer example is broken when trying to import from just /deprecated, as demonstrated below:
https://user-images.githubusercontent.com/7115053/227536041-57bb9c78-8254-412a-84aa-97d245df1b8a.mov

And with this change:
https://user-images.githubusercontent.com/7115053/227539676-a7df08f2-44da-4f11-9df5-f1ed47e8bb23.mov

Based on this testing I think everything is good to go functionality wise, but since I don't think I fully understand the reasoning behind the approach you went with previously I figured it would be best to double check with you.

Copy link
Contributor

Choose a reason for hiding this comment

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

I went ahead and tested this out against a sample project to make sure /deprecated and /next components can still be imported from @patternfly/react-core/next and @patternfly/react-core/deprecated (which was the point of the change in the first place). Just testing within this repo is less reliable IMO, but certainly the documentation working as expected is a good sign.

} else {
return contents.replaceAll('./', `../dist/esm/${subPathName}/`);
}
};

['deprecated', 'components'].forEach((subPathName) => {
const distPath = resolve(__dirname, `../dist/esm/${subPathName}`);
const distFileNames = readdirSync(distPath);
const distIndexFileNames = distFileNames.filter((fileName) => isIndex(fileName));

const destinationDir = resolve(__dirname, `../${subPathName}`);
mkdirSync(destinationDir, { recursive: true });

distIndexFileNames.forEach((fileName) => {
const filePath = join(__dirname, '../dist/esm', subPathName, fileName);
const newFileContent = updatePaths(filePath, subPathName);
const fileDestination = join(destinationDir, fileName);
writeFileSync(fileDestination, newFileContent);
});
});