Skip to content

V2 : fix rebuild geometry for cli#583

Merged
kaosat-dev merged 4 commits intoV2from
v2-fix-rebuild-geometry-for-cli
May 21, 2020
Merged

V2 : fix rebuild geometry for cli#583
kaosat-dev merged 4 commits intoV2from
v2-fix-rebuild-geometry-for-cli

Conversation

@z3dev
Copy link
Copy Markdown
Member

@z3dev z3dev commented May 17, 2020

These changes adjust the logic in rebuildGeometryCli() to ONLY use webRequire() when a conversion to JSCAD source happens, e.g. STL translation. The opposite is also true, the logic ONLY uses require() in normal cases.

Fixes #504 for the CLI only.
Fixes conversions from STL to DXF, etc. (test case has been enabled)

I always wondered why webRequire() was used by rebuildGeometryCli(), and now I understand. There's a special case when external formats are converted in-memory, which webRequire() handles nicely.

All Submissions:

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same update/change?
  • Does your submission pass tests?

z3dev added 2 commits May 17, 2020 09:50
…e is NO conversion

enabled test of stl to dxf conversion
@z3dev z3dev requested a review from kaosat-dev May 20, 2020 01:40
@z3dev
Copy link
Copy Markdown
Member Author

z3dev commented May 20, 2020

@kaosat-dev please review.

by the way, if we want to enforce 'projects' then we should block single file scripts, or warn if single file scripts are used. Issue #504. what do you think?

Copy link
Copy Markdown
Contributor

@kaosat-dev kaosat-dev left a comment

Choose a reason for hiding this comment

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

Hi @z3dev mostly a few minor tweaks and clarification needed please, thanks !

const fakeFs = makeFakeFs(filesAndFolders)
requireFn = makeWebRequire(filesAndFolders, { apiMainPath, fakeFs })// hasRequire() ? require : makeWebRequire(filesAndFolders, { apiMainPath })
// register all extension formats
registerAllExtensions(fakeFs, requireFn)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

if this is not present, require('foo.stl') will not work

Copy link
Copy Markdown
Member Author

@z3dev z3dev May 20, 2020

Choose a reason for hiding this comment

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

CLI generateOutputData() calls this function with the normal file system and NODEJS require(), so the extensions are registered.
The call is not necessary for converted/transformed sources.
Also, there's a test case for this as well, which passes.


// console.log('transformed sources', filesAndFolders)
// now check if we need fake require or not
// FIXME: we need to come up with a way to intercept node 'require' calls to be able to apply transformSources on the fly
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Unless this is fixed, please leave as is :)
Removing console.log() debug statements is good, but TODO/FIXMEs are there for a reason

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

FIXME: we need to come up with a way to intercept node 'require' calls to be able to apply transformSources on the fly

I think is is fixed. The call to registerAllExtensions() makes this possible. And a very cool solution as well.

if (!inputIsDirectory) {

// source came from conversion, i.e. not from file system
if (data.source) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

A few questions for clarity please:

  • can we not reuse the inputIsDirectory in this case ? is there any difference ?
  • why is mainPath overwritten ? ie does this get triggered only if there is a single input script ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I added the source versus prevsource to determine if the conversion took place. And adjusted rebuildGeometryCli() to use webRequire() if a source (converted source) is present.

The use of inputIsDirectory for single files was causing issues when *.stl, etc. files were passed in. For example, ./cli.js my.stl -of dxf

The use of data.source is not ideal. It would better be better to use a real option, i.e. isFromConversion.

For the webrequire to work properly, both fullPath and mainPath need to be the same. We could derive a 'in-memory' name from the original mainPath, but I don't see the reason.

Copy link
Copy Markdown
Member Author

@z3dev z3dev May 21, 2020

Choose a reason for hiding this comment

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

@kaosat-dev please review again.

after thinking about this conversation, i changed the logic slightly. there's a new option to rebuildGeometryCli called 'useFakeFs'. This option requestes rebuildGeometryCli to create a fake file system, and of course use webRequire as well.

z3dev added 2 commits May 21, 2020 12:10
changed code to derive fake file name and path from given mainPath
code cleanup
@kaosat-dev kaosat-dev merged commit 828394d into V2 May 21, 2020
@z3dev z3dev deleted the v2-fix-rebuild-geometry-for-cli branch June 9, 2020 08:44
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.

2 participants