fluidcad 0.0.6 → 0.0.7

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": "fluidcad",
3
- "version": "0.0.6",
3
+ "version": "0.0.7",
4
4
  "description": "Parametric CAD modeling library using javascript",
5
5
  "author": "Marwan Aouida <contact@marwan.dev>",
6
6
  "homepage": "https://fluidcad.io",
@@ -24,6 +24,19 @@ function getBlockedNodeModule(id) {
24
24
  const baseName = name.split('/')[0];
25
25
  return BLOCKED_NODE_MODULES.has(baseName) ? baseName : null;
26
26
  }
27
+ const IMPORT_PATTERN = /\b(?:import|export)\s[\s\S]*?from\s+['"]([^'"]+)['"]|\bimport\s*\(\s*['"]([^'"]+)['"]\s*\)/g;
28
+ function scanForBlockedImports(code) {
29
+ let match;
30
+ IMPORT_PATTERN.lastIndex = 0;
31
+ while ((match = IMPORT_PATTERN.exec(code)) !== null) {
32
+ const specifier = match[1] || match[2];
33
+ const blocked = getBlockedNodeModule(specifier);
34
+ if (blocked) {
35
+ return specifier;
36
+ }
37
+ }
38
+ return null;
39
+ }
27
40
  export class ViteManager {
28
41
  server;
29
42
  rootPath = '';
@@ -47,11 +60,6 @@ export class ViteManager {
47
60
  {
48
61
  name: 'virtual-module',
49
62
  resolveId(id, importer) {
50
- const blockedModule = getBlockedNodeModule(id);
51
- if (blockedModule) {
52
- throw new Error(`Module "${id}" is not allowed in FluidCAD scripts. ` +
53
- `Access to Node.js "${blockedModule}" module is restricted for security.`);
54
- }
55
63
  if (id.startsWith('virtual:')) {
56
64
  return id;
57
65
  }
@@ -61,6 +69,16 @@ export class ViteManager {
61
69
  return resolve(dirname(realImporter), id);
62
70
  }
63
71
  },
72
+ transform(code, id) {
73
+ if (id.startsWith(rootPath) || id.startsWith('virtual:live-render')) {
74
+ const blocked = scanForBlockedImports(code);
75
+ if (blocked) {
76
+ const moduleName = getBlockedNodeModule(blocked);
77
+ throw new Error(`Module "${blocked}" is not allowed in FluidCAD scripts. ` +
78
+ `Access to Node.js "${moduleName}" module is restricted for security.`);
79
+ }
80
+ }
81
+ },
64
82
  load(id) {
65
83
  if (id.startsWith('virtual:live-render')) {
66
84
  let mod = this.getModuleInfo(id);