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

Split into create-modular-react-app and modular-scripts packages #29

Merged
merged 1 commit into from
Jul 14, 2020

Conversation

sebinsua
Copy link
Contributor

@sebinsua sebinsua commented Jul 13, 2020

Split into create-modular-react-app and modular-scripts packages.

Also, generate the widgets map at transpilation time.

package.json Outdated
@@ -9,7 +9,8 @@
"scripts": {
"prettier": "prettier --write .",
"lint": "eslint --cache --fix --ext .js,.ts,.tsx --max-warnings 0 .",
"test": "jest"
"test": "jest",
"build": "workspaces-run --ignore eslint-config-modular -- yarn build"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yet again I run into that problem where yarn workspaces run doesn't have a way of excluding packages in v1.

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 need to have all this as one command (which we then need to fix by adding yet another dependency). let's just have separate build commands for each package.

stdout: process.stdout,
...opts,
});
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is now defined in both of the packages...

Copy link
Contributor

Choose a reason for hiding this comment

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

that's fine, don't sweat it. we shouldn't be afraid of copy pasted code, especially when it's as low stakes as this

} catch (err) {
return false;
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is also now defined in both of the packages.

@sebinsua sebinsua force-pushed the create-modular-app branch from f4355c6 to 8b1326f Compare July 13, 2020 19:14
if (!name) {
console.error('Please pass a name into `create-modular-app`.');
process.exit(1);
}
Copy link
Contributor Author

@sebinsua sebinsua Jul 13, 2020

Choose a reason for hiding this comment

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

I dropped meow from this package but then needed the positional argument which followed create-modular-app to be treated as the application name.

This code is kind of weird because I was worried by all of the different ways it could be executed (e.g. npx create-modular-app, yarn create modular-app, npm init modular-app, and so on...)

Does anybody have a better idea?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm fine with using/recommending just one one (npx) even if we force yarn for the rest.

workspaces: ['app', 'widgets/*'],
modular: {},
scripts: {
start: 'modular-scripts start',
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 think we should add a add-widget script into this or something like that?

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 so. Should be ok.

// TODO: Enable these once published.
// 'modular-scripts',
// TODO: This config needs to be given a different name.
// 'eslint-config-modular',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This package name already exists. Does anybody have another?

Copy link
Contributor

Choose a reason for hiding this comment

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

eslint-config-modular-app

delete appPackageJson['scripts'];
delete appPackageJson['eslintConfig'];
/* eslint-enable @typescript-eslint/no-unsafe-member-access */
fs.writeJsonSync(appPackageJsonPath, appPackageJson);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Quite a lot of the code above should belong to a cra-template.

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah, let's do that right after this.


// TODOS
// - make sure react/react-dom have the same versions across the repo
// fix stdio coloring
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Additionally, is it an issue that CRA prints messages about commands it's made available, which aren't available (e.g. yarn eject). Hiding messages seems like a total mess...

Copy link
Contributor

Choose a reason for hiding this comment

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

don't worry about it. remember that we'll fallback to regular CRA after facebook/create-react-app#1333 is resolved (maybe)

@@ -0,0 +1,10 @@
// DO NOT EDIT THIS FILE.
// eslint-disable-next-line import/no-extraneous-dependencies
Copy link
Contributor Author

@sebinsua sebinsua Jul 13, 2020

Choose a reason for hiding this comment

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

Sorry about this. I tried creating an .eslintignore for the template directory but it had no effect.

const { getModularRoot, generateWidgetMap } = require('modular-scripts');

module.exports = generateWidgetMap(path.join(getModularRoot(), 'widgets'));
`;
Copy link
Contributor Author

@sebinsua sebinsua Jul 13, 2020

Choose a reason for hiding this comment

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

The other way of doing this would be: with the separate modular map command or via a webpack plugin.

I think the separate command made the scripts code more complicated because map was run during other commands to keep the code and directories in sync.

While the special wepback virtuals modules plugin is that it's webpack-specific.

This makes the source of truth clearer, however the con is that it's showing people 'how the sausage is made'.

Copy link
Contributor

Choose a reason for hiding this comment

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

does this work with babel's caching? add a widget, and see if the map updates. I'm not sure it will, unless this issue's been fixed recently.

If that doesn't work, I think manually generating might still be the right thing to do for now. This should probably have been in a separate PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

Further, assuming we're going to start recommending typescript (or some static type system) as the default, how would this work?

Strongly leaning towards keeping the manual method for longer than we'd think.

Copy link
Contributor Author

@sebinsua sebinsua Jul 13, 2020

Choose a reason for hiding this comment

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

I remember the caching problem you're talking about and it's still not fixed, however ...it seems to be working.

I am not sure why though? It could be because of the yarn add ... or the call to yarn prettier. I guess it would be bugged, if somebody mutated the file-system without using modular-scripts add [widget-name]? Deal-breaker? Update: I tried without those, and we need some form of yarn install, to make the packages available in the workspace, however it appears to regenerate that file no matter what. I have no idea why it's working.

I noticed that the cache issue has this comment against it: > **Note**: This issue is not present when used in Create React App. This refers to this comment.

Here's the fix.

I don't really like that there is a command which people need to know about in addition to the command to add a widget, but on the other hand I'm not asserting that this is actually a good solution... 👀

If this was rewritten to have static typing, I was going to suggest that this output into a function body, and then set the type with the return type of this. export default getWidgetMap();

# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
node_modules
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This isn't the original CRA .gitignore, since that only ignored the root-level /node_modules.

description: 'Dashboards for a new generation',
help: `
Usage:
$ modular-scripts add <name>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is modular-scripts add a good name or does yarn modular-scripts add feel confusingly like yarn add?

Copy link
Contributor

Choose a reason for hiding this comment

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

can't we name the bin modular?

Copy link
Contributor Author

@sebinsua sebinsua Jul 13, 2020

Choose a reason for hiding this comment

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

What do others think? I changed the name to be in line with react-scripts, kcd-scripts, etc. But we could have a package called modular-scripts (or even something scoped) which created a binary called modular. That's also OK.

Copy link
Contributor

Choose a reason for hiding this comment

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

But we could have a package called modular-scripts (or even something scoped) which created a binary called modular. That's also OK.

yeah this is what I meant. I still think we'll eventually get the package name fwiw.

Copy link
Contributor

Choose a reason for hiding this comment

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

You can have diff bin names and package names, although maybe for a modular bin I'd expect @modular/cli or modular-cli?

@@ -0,0 +1,2 @@
export * from './getModularRoot';
export * from './generateWidgetMap';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These are now used by the app/src/widgets.js created by create-modular-app.


test('it should render', () => {
const el = document.createElement('div');
expect(() => render(<Component$$ />, el)).not.toThrow();
expect(() => render(<ComponentName$$ />, el)).not.toThrow();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was a bug within my last PR.

Copy link
Contributor

@threepointone threepointone left a comment

Choose a reason for hiding this comment

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

stamping

@sebinsua sebinsua force-pushed the create-modular-app branch from d22d57b to 7ed2117 Compare July 14, 2020 11:51
@sebinsua sebinsua changed the title Split into create-modular-app and modular-scripts packages Split into create-modular-react-app and modular-scripts packages Jul 14, 2020
@sebinsua sebinsua force-pushed the create-modular-app branch from 7ed2117 to bc1df24 Compare July 14, 2020 11:52
Also, generate the widgets map at transpilation time.
@sebinsua sebinsua force-pushed the create-modular-app branch from bc1df24 to 34c8853 Compare July 14, 2020 11:55
@sebinsua sebinsua merged commit f123294 into master Jul 14, 2020
@sebinsua sebinsua deleted the create-modular-app branch July 14, 2020 11:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants