@jscad/core 2.5.9 → 2.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jscad/core",
3
- "version": "2.5.9",
3
+ "version": "2.6.2",
4
4
  "description": "Core functionality for JSCAD Applications",
5
5
  "homepage": "https://openjscad.xyz/",
6
6
  "repository": "https://github.com/jscad/OpenJSCAD.org",
@@ -36,9 +36,9 @@
36
36
  "license": "MIT",
37
37
  "dependencies": {
38
38
  "@jscad/array-utils": "2.1.4",
39
- "@jscad/io": "2.3.2",
40
- "@jscad/io-utils": "2.0.18",
41
- "@jscad/modeling": "2.9.3",
39
+ "@jscad/io": "2.4.1",
40
+ "@jscad/io-utils": "2.0.21",
41
+ "@jscad/modeling": "2.9.6",
42
42
  "json5": "2.2.0",
43
43
  "strip-bom": "4.0.0"
44
44
  },
@@ -53,5 +53,5 @@
53
53
  "url": "https://opencollective.com/openjscad",
54
54
  "logo": "https://opencollective.com/openjscad/logo.txt"
55
55
  },
56
- "gitHead": "85fa1fcdfb2d516a201ecf31da242e64b5b3274e"
56
+ "gitHead": "9768af96e5da00cd113c00ddeb0f6046707819b1"
57
57
  }
@@ -17,9 +17,12 @@ const applyParameterDefinitions = require('../parameters/applyParameterDefinitio
17
17
  * @param {Object} [data.parameterValues] - over-rides of parameter values (optional)
18
18
  * @param {Function} callback - function to process parameters and solids
19
19
  * @return NONE
20
+ *
20
21
  * This function extracts the parameters first, and then generates the solids.
21
22
  * The parsed parameters (definitions and values) are passed back to the given callback function.
22
23
  * The generated solids are also passed back to the given callback function.
24
+ * Also, all errors are caught and passed back to the given callback function.
25
+ *
23
26
  * Everything is together in a single function, because this is usually run in the context of a web worker
24
27
  * And transfering data back & forth is both complex (see transferables) and costly (time)
25
28
  **/
@@ -34,37 +37,51 @@ const rebuildSolids = (data, callback) => {
34
37
  }
35
38
  let { mainPath, apiMainPath, serialize, lookup, lookupCounts, parameterValues } = Object.assign({}, defaults, data)
36
39
 
37
- const filesAndFolders = data.filesAndFolders
40
+ try {
41
+ const filesAndFolders = data.filesAndFolders
38
42
 
39
- // let start = new Date()
40
- const designData = loadDesign(mainPath, apiMainPath, filesAndFolders, parameterValues)
41
- // send back parameter definitions & values
42
- // in a worker this would be a postmessage, this is sent back early so that uis can update
43
- // the parameters editor before the solids are displayed (which takes longer)
44
- callback(null, {
45
- type: 'params',
46
- parameterDefaults: designData.parameterValues,
47
- parameterDefinitions: designData.parameterDefinitions
48
- })
49
- // make sure parameters are correct by applying parameter definitions
50
- // this might be redundant with ui-side logic, but it makes sure this core piece works regardless of ui
51
- parameterValues = applyParameterDefinitions(parameterValues, designData.parameterDefinitions)
52
- parameterValues = Object.assign({}, designData.parameterValues, parameterValues)
53
- // start = new Date()
54
- const options = {
55
- lookup,
56
- lookupCounts,
57
- serialize
58
- }
59
- const solidsData = instanciateDesign(designData.rootModule, parameterValues, options)
43
+ // let start = new Date()
44
+ const designData = loadDesign(mainPath, apiMainPath, filesAndFolders, parameterValues)
45
+ // send back parameter definitions & values
46
+ // in a worker this would be a postmessage, this is sent back early so that uis can update
47
+ // the parameters editor before the solids are displayed (which takes longer)
48
+ callback(null, {
49
+ type: 'params',
50
+ parameterDefaults: designData.parameterValues,
51
+ parameterDefinitions: designData.parameterDefinitions
52
+ })
53
+ // make sure parameters are correct by applying parameter definitions
54
+ // this might be redundant with ui-side logic, but it makes sure this core piece works regardless of ui
55
+ parameterValues = applyParameterDefinitions(parameterValues, designData.parameterDefinitions)
56
+ parameterValues = Object.assign({}, designData.parameterValues, parameterValues)
57
+ // start = new Date()
58
+ const options = {
59
+ lookup,
60
+ lookupCounts,
61
+ serialize
62
+ }
63
+ const solidsData = instanciateDesign(designData.rootModule, parameterValues, options)
60
64
 
61
- // send back solids & any other metadata
62
- callback(null, {
63
- type: 'solids',
64
- solids: solidsData.solids,
65
- lookup: solidsData.lookup,
66
- lookupCounts: solidsData.lookupCounts
67
- })
65
+ // send back solids & any other metadata
66
+ callback(null, {
67
+ type: 'solids',
68
+ solids: solidsData.solids,
69
+ lookup: solidsData.lookup,
70
+ lookupCounts: solidsData.lookupCounts
71
+ })
72
+ } catch (error) {
73
+ callback({
74
+ type: 'errors',
75
+ name: error.name ? error.name : 'Error',
76
+ message: error.message ? error.message : error.toString(),
77
+ description: error.description ? error.description : '',
78
+ number: error.number ? error.number : '',
79
+ fileName: error.fileName ? error.fileName : '',
80
+ lineNumber: error.lineNumber ? error.lineNumber : '',
81
+ columnNumber: error.columnNumber ? error.columnNumber : '',
82
+ stack: error.stack ? error.stack : ''
83
+ }, null)
84
+ }
68
85
  }
69
86
 
70
87
  module.exports = rebuildSolids
@@ -13,7 +13,10 @@ const rebuildGeometryWorker = (self) => {
13
13
  if (event.data instanceof Object) {
14
14
  const { data } = event
15
15
  if (data.cmd === 'generate') {
16
- rebuildGeometry(data, (err, message) => self.postMessage(message))
16
+ rebuildGeometry(data, (error, message) => {
17
+ if (message) self.postMessage(message)
18
+ if (error) self.postMessage(error)
19
+ })
17
20
  }
18
21
  }
19
22
  }
@@ -111,15 +111,31 @@ const makeWebRequire = (filesAndFolders, options) => {
111
111
  const matchingModule = {
112
112
  exports: {},
113
113
  _compile: (content, fileName) => {
114
- const moduleMakerFunction = new Function('require', 'module', content) // eslint-disable-line no-new-func
115
- moduleMakerFunction(_require.bind(null, entry.fullPath), matchingModule)
114
+ try {
115
+ const moduleMakerFunction = new Function('require', 'module', content) // eslint-disable-line no-new-func
116
+ moduleMakerFunction(_require.bind(null, entry.fullPath), matchingModule)
117
+ } catch (e) {
118
+ // catch errors and build a context specific error, with file name and stack trace
119
+ // the stack trace mimics the style of nodejs
120
+ const message = e.message
121
+ fileName = fileName.replace('/', '')
122
+ // NOTE: only firefox provides line and column numbers
123
+ const lineNumber = e.lineNumber ? e.lineNumber - 2 : 0 // the call to Function (above) adds two lines
124
+ const columnNumber = e.columnNumber ? e.columnNumber : 0
125
+ if (e.stack.startsWith('Object')) {
126
+ e.stack = `${e.stack}\nObject.<anonymous> (${fileName}:${lineNumber}:${columnNumber})`
127
+ } else {
128
+ e = new SyntaxError(message, fileName, lineNumber)
129
+ e.columnNumber = columnNumber
130
+ e.stack = `Object.<anonymous> (${fileName}:${lineNumber}:${columnNumber})`
131
+ }
132
+ throw e
133
+ }
116
134
 
117
135
  const paramDefFromSource = content.includes('@jscad-params') ? getParameterDefinitionsFromSource(content, fileName) : []
118
136
  const originalFunc = matchingModule.exports.getParameterDefinitions
119
137
  // replace getParameterDefinitions in the module, with version taht adds parsed definitions
120
138
  matchingModule.exports.getParameterDefinitions = () => combineParameterDefinitions(paramDefFromSource, originalFunc ? originalFunc() || [] : [])
121
- // add to core to resolve later references
122
- // FIXME coreModules[entry.fullPath] = matchingModule.exports
123
139
  }
124
140
  }
125
141
  extensions[baseExt](matchingModule, entry.fullPath)