@jscad/core 2.5.2 → 2.5.3

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.2",
3
+ "version": "2.5.3",
4
4
  "description": "Core functionality for JSCAD Applications",
5
5
  "repository": "https://github.com/jscad/OpenJSCAD.org",
6
6
  "main": "src/index.js",
@@ -35,7 +35,7 @@
35
35
  "license": "MIT",
36
36
  "dependencies": {
37
37
  "@jscad/array-utils": "2.1.1",
38
- "@jscad/io": "2.2.2",
38
+ "@jscad/io": "2.2.3",
39
39
  "@jscad/io-utils": "2.0.12",
40
40
  "@jscad/modeling": "2.7.1",
41
41
  "json5": "2.2.0",
@@ -52,5 +52,5 @@
52
52
  "url": "https://opencollective.com/openjscad",
53
53
  "logo": "https://opencollective.com/openjscad/logo.txt"
54
54
  },
55
- "gitHead": "c8ac21281a7acf5a5575b940c18353c598ffa1a4"
55
+ "gitHead": "95f05c5f11a53bff469a305d69b99f674dc7d6d3"
56
56
  }
@@ -3,17 +3,17 @@
3
3
  */
4
4
  const normalizeDesignModule = (rootModule) => {
5
5
  if (!rootModule) {
6
- throw new Error('no root module found')
6
+ throw new Error('no root module found, please check the project structure')
7
7
  }
8
8
  if (typeof (rootModule) === 'function') {
9
- console.warn('please use named exports for the main() function')
9
+ console.warn('please refactor the exports, assigning main() as a property, i.e. module.exports = { main }')
10
10
  rootModule = { main: rootModule }
11
11
  }
12
12
  if (!rootModule.main) {
13
- throw new Error('no main() function, check the exports')
13
+ throw new Error('no main() function found, please check the module.exports')
14
14
  }
15
- if (!(typeof (rootModule.main) === 'function')) {
16
- throw new Error('main is not a function, check the exports')
15
+ if (typeof (rootModule.main) !== 'function') {
16
+ throw new Error('main is not a function, please check the module.exports')
17
17
  }
18
18
  return rootModule
19
19
  }
@@ -1,18 +1,10 @@
1
1
  const { deserializers } = require('@jscad/io')
2
2
 
3
- const isCommonJsModule = require('./isCommonJsModule')
4
- const modulifySource = require('./modulifySource')
5
-
6
- const passThroughTransform = (options, entry) => entry
7
-
8
- /* function to turn old style jscad code with implicit imports
9
- into code with explicit exports/imports */
10
- // FIXME wouldn't a javascript error be better then 'hacking' the users code?
3
+ /*
4
+ * Transform the entry into a ready-to-use module.
5
+ */
11
6
  const modulifyTransform = (options, entry) => {
12
- const { apiMainPath } = options
13
- const isFileCommonJs = isCommonJsModule(entry.source)
14
- const source = !isFileCommonJs ? modulifySource(entry.source, apiMainPath) : entry.source
15
- return Object.assign({}, entry, { source })
7
+ return Object.assign({}, entry, { source: entry.source })
16
8
  }
17
9
 
18
10
  /*
@@ -72,6 +72,7 @@ const makeWebRequire = (filesAndFolders, options) => {
72
72
  // console.log('*****\n',filesAndFolders,'\n*****')
73
73
 
74
74
  const extensions = {}
75
+ const moduleCache = {}
75
76
 
76
77
  /* Require (obtain) the exports for the given require path, relative to the given current path.
77
78
  * The logic is based on the original NODE require() function.
@@ -105,6 +106,7 @@ const makeWebRequire = (filesAndFolders, options) => {
105
106
  if (entry.children) return null // directory
106
107
 
107
108
  if (extensions[baseExt]) {
109
+ if(moduleCache[requirePath]) return moduleCache[requirePath]
108
110
  // evaluate the content
109
111
  const matchingModule = {
110
112
  exports: {},
@@ -121,7 +123,7 @@ const makeWebRequire = (filesAndFolders, options) => {
121
123
  }
122
124
  }
123
125
  extensions[baseExt](matchingModule, entry.fullPath)
124
- return matchingModule.exports
126
+ return moduleCache[requirePath] = matchingModule.exports
125
127
  }
126
128
  return null
127
129
  }
@@ -13,10 +13,14 @@ test('webRequire: should support require, from a single file', (t) => {
13
13
 
14
14
  let requireFn = makeWebRequire(singleFileJs, { apiMainPath })
15
15
  let designRootModule = requireFn(singleFileJs[0].fullPath)
16
+ const designRootModule2 = requireFn(singleFileJs[0].fullPath)
16
17
 
17
18
  t.true('main' in designRootModule)
18
19
  t.true(designRootModule.main instanceof Function)
19
20
 
21
+ t.is(designRootModule, designRootModule2)
22
+ t.deepEqual(designRootModule, designRootModule2)
23
+
20
24
  // NOTE: 'jscad' must be registered as an extension
21
25
  const fakeFs = makeFakeFs(singleFileJscad)
22
26
  requireFn = makeWebRequire(singleFileJscad, { apiMainPath })
@@ -32,7 +36,6 @@ test('webRequire: should support require, from a directory with index.js', (t) =
32
36
 
33
37
  const requireFn = makeWebRequire(directoryWithIndexJs, { apiMainPath })
34
38
  const designRootModule = requireFn('/project')
35
-
36
39
  t.true('main' in designRootModule)
37
40
  t.true(designRootModule.main instanceof Function)
38
41
  })