Skip to content

Implement page copying into generated from original theme (in case you starting with existing app)#7

Open
linq2js wants to merge 4 commits into
shopify-nextjs-modulesfrom
hung.nguyen/copying-pages
Open

Implement page copying into generated from original theme (in case you starting with existing app)#7
linq2js wants to merge 4 commits into
shopify-nextjs-modulesfrom
hung.nguyen/copying-pages

Conversation

@linq2js
Copy link
Copy Markdown

@linq2js linq2js commented Feb 22, 2021

Implement page copying into generated from original theme (in case you starting with existing app)

Copy link
Copy Markdown

@yeegor yeegor left a comment

Choose a reason for hiding this comment

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

Overall, the functionality seems good, although some modifications are required logc-wise and coding style-wise. Please, provide them, then we'll do a CR again!

Additional comment: please, make sure that require.resolve works OK in the modules with these changed imports. It seems that it currently is not handled, although on server side it sometimes is used.

Comment thread next-packages/nextjs-scripts/lib/pages.js Outdated
Comment thread next-packages/nextjs-scripts/lib/pages.js Outdated
Comment thread next-packages/nextjs-scripts/lib/pages.js Outdated
Comment on lines +2 to +24
"name": "@scandipwa/nextjs-scripts",
"description": "Scripts and configuration used by CSA.",
"version": "0.0.0",
"bin": {
"nextjs-scripts": "./bin/nextjs-scripts.js"
},
"engines": {
"node": ">=12.0.0"
},
"dependencies": {
"@scandipwa/scandipwa-dev-utils": "^0.0.20",
"chokidar": "^3.5.1",
"cross-spawn": "^7.0.3",
"debounce": "^1.2.0",
"glob": "^7.1.6",
"next": "10.0.5",
"tree-kill": "^1.2.2",
"@babel/preset-react": "^7.12.13"
},
"license": "OSL-3.0",
"publishConfig": {
"access": "public"
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pls keep this intact if you did not modify actual contents. Same as one of the comments above.

} = parts.shift();

result.push(source.substring(lastIndex, start));
const code = source.substring(start, end);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

code is not the most verbose name for this. Maybe importSource?
source is also code. Please, rename this :)

Comment thread next-packages/nextjs-scripts/lib/pages.js Outdated
Comment on lines +58 to +63
code.replace(/[`'"]([^`'"]+)[`'"]/, (match, value) => {
const resolvedModulePath = tranformer(value);

return `"${resolvedModulePath}"`;
})
);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

If you have the sources' values as described above, you will be able to just cut away first and last symbol to get rid of the quote marks, instead of matching them by regex. That could be a tiny bit faster, and work more stable.

Comment thread next-packages/nextjs-scripts/lib/pages.js Outdated
Comment thread next-packages/shopify-nextjs-theme/src/pages/TestPage.js Outdated
Comment thread next-packages/shopify-nextjs-theme/src/util.js Outdated
Copy link
Copy Markdown

@yeegor yeegor left a comment

Choose a reason for hiding this comment

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

The functionality seems valid.
Although, mutating external data within array methods is considered bad practice. Please see the comments.

Comment on lines +89 to +90
.forEach(([sourceFile,
targetFile]) => {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Splitting this into 2 lines is against our coding style. Please make this oneline.

Comment on lines +59 to +63
importSource.replace(/[`'"]([^`'"]+)[`'"]/, (match, value) => {
const resolvedModulePath = transformer(value);

return `"${ resolvedModulePath }"`;
})
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Still, CallExpression nodes are used instead of sources within the nodes. Why so? See the previous CR for details. This would free you of this regexp.

hung.nguyen added 2 commits March 10, 2021 17:08
Optimize import source resolving
Show warning with dynamic import/require calls
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants