@bleedingdev/modern-js-sandpack-react 3.2.0-ultramodern.98 → 3.4.0-ultramodern.0

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.
@@ -0,0 +1,30 @@
1
+ .DS_Store
2
+
3
+ .pnp
4
+ .pnp.js
5
+ .env.local
6
+ .env.*.local
7
+ .history
8
+ *.log*
9
+
10
+ node_modules/
11
+ .yarn-integrity
12
+ .pnpm-store/
13
+ *.tsbuildinfo
14
+ .changeset/pre.json
15
+
16
+ dist/
17
+ coverage/
18
+ release/
19
+ output/
20
+ output_resource/
21
+ log/
22
+
23
+ .vscode/**/*
24
+ !.vscode/settings.json
25
+ !.vscode/extensions.json
26
+ .idea/
27
+
28
+ **/*/typings/auto-generated
29
+
30
+ modern.config.local.*
@@ -0,0 +1,2 @@
1
+ lts/jod
2
+
@@ -0,0 +1,32 @@
1
+ # Modern.js App
2
+
3
+ ## Setup
4
+
5
+ Install the dependencies:
6
+
7
+ ```bash
8
+ pnpm install
9
+ ```
10
+
11
+ ## Get Started
12
+
13
+ Start the start server:
14
+
15
+ ```bash
16
+ pnpm start
17
+ ```
18
+
19
+ Build the app for production:
20
+
21
+ ```bash
22
+ pnpm build
23
+ ```
24
+
25
+ Preview the production build locally:
26
+
27
+ ```bash
28
+ pnpm serve
29
+ ```
30
+
31
+ For more information, see the [Modern.js documentation](https://modernjs.dev/en).
32
+
@@ -0,0 +1,37 @@
1
+ {
2
+ "$schema": "https://biomejs.dev/schemas/1.9.4/schema.json",
3
+ "vcs": {
4
+ "enabled": true,
5
+ "defaultBranch": "main",
6
+ "clientKind": "git",
7
+ "useIgnoreFile": true
8
+ },
9
+ "formatter": {
10
+ "enabled": true,
11
+ "indentStyle": "space"
12
+ },
13
+ "javascript": {
14
+ "formatter": {
15
+ "quoteStyle": "single",
16
+ "arrowParentheses": "asNeeded",
17
+ "jsxQuoteStyle": "double",
18
+ "lineWidth": 80
19
+ }
20
+ },
21
+ "linter": {
22
+ "enabled": true,
23
+ "rules": {
24
+ "recommended": true,
25
+ "suspicious": {
26
+ "noDuplicateFontNames": "off"
27
+ }
28
+ }
29
+ },
30
+ "organizeImports": {
31
+ "enabled": true
32
+ },
33
+ "files": {
34
+ "ignoreUnknown": true,
35
+ "ignore": [".vscode/**/*", "node_modules/**/*", "dist/**/*"]
36
+ }
37
+ }
@@ -0,0 +1,27 @@
1
+ {
2
+ "name": "{{packageName}}",
3
+ "version": "0.1.0",
4
+ "scripts": {
5
+ "dev": "modern dev",
6
+ "build": "modern build",
7
+ "serve": "modern serve"{{#unless isSubproject}},
8
+ "lint": "biome check"{{/unless}}
9
+ },
10
+ "engines": {
11
+ "node": ">=20"
12
+ },
13
+ "dependencies": {
14
+ "@modern-js/runtime": "{{version}}",
15
+ "react": "^19.2.3",
16
+ "react-dom": "^19.2.0"
17
+ },
18
+ "devDependencies": {
19
+ "@modern-js/app-tools": "{{version}}",
20
+ "@modern-js/tsconfig": "{{version}}"{{#unless isSubproject}},
21
+ "@biomejs/biome": "1.9.4"{{/unless}},
22
+ "typescript": "~5.7.3",
23
+ "@types/node": "^20",
24
+ "@types/react": "^19.1.8",
25
+ "@types/react-dom": "^19.1.6"
26
+ }
27
+ }
@@ -1,5 +1,4 @@
1
- import { renderString } from '@modern-js/codesmith-api-handlebars';
2
- import { fs } from '@modern-js/codesmith-utils/fs-extra';
1
+ import fs from 'node:fs';
3
2
  import { createRequire } from 'module';
4
3
  import path from 'path';
5
4
  import recursive from 'recursive-readdir';
@@ -14,6 +13,80 @@ const IgnoreFiles = [
14
13
  'README.md',
15
14
  ];
16
15
 
16
+ function renderTemplate(
17
+ template: string,
18
+ data: Record<string, unknown>,
19
+ ): string {
20
+ type ConditionalKind = 'if' | 'unless';
21
+ const tagRegex = /\{\{(~?)(#if|#unless|\/if|\/unless)(?:\s+(\w+))?(~?)\}\}/g;
22
+
23
+ function renderConditionals(
24
+ startIndex: number,
25
+ expectedClose?: ConditionalKind,
26
+ ): {
27
+ rendered: string;
28
+ nextIndex: number;
29
+ } {
30
+ let rendered = '';
31
+ let cursor = startIndex;
32
+ tagRegex.lastIndex = startIndex;
33
+
34
+ while (true) {
35
+ const match = tagRegex.exec(template);
36
+ if (!match) {
37
+ return {
38
+ rendered: rendered + template.slice(cursor),
39
+ nextIndex: template.length,
40
+ };
41
+ }
42
+
43
+ const [raw, , tag, condition, rightTrim] = match;
44
+ const tagIndex = match.index;
45
+ rendered += template.slice(cursor, tagIndex);
46
+ cursor = tagIndex + raw.length;
47
+
48
+ if (tag === '#if' || tag === '#unless') {
49
+ const kind: ConditionalKind = tag === '#if' ? 'if' : 'unless';
50
+ const innerResult = renderConditionals(cursor, kind);
51
+ cursor = innerResult.nextIndex;
52
+ tagRegex.lastIndex = cursor;
53
+
54
+ const conditionValue = Boolean(data[condition ?? '']);
55
+ const shouldInclude = kind === 'if' ? conditionValue : !conditionValue;
56
+ if (shouldInclude) {
57
+ rendered += innerResult.rendered;
58
+ }
59
+ continue;
60
+ }
61
+
62
+ if (tag === '/if' || tag === '/unless') {
63
+ const kind: ConditionalKind = tag === '/if' ? 'if' : 'unless';
64
+ if (expectedClose === kind) {
65
+ let nextIndex = cursor;
66
+ if (rightTrim === '~') {
67
+ const trailingWhitespace = /^\s*/u.exec(template.slice(nextIndex));
68
+ nextIndex += trailingWhitespace?.[0].length ?? 0;
69
+ }
70
+ return {
71
+ rendered,
72
+ nextIndex,
73
+ };
74
+ }
75
+ rendered += raw;
76
+ }
77
+ }
78
+ }
79
+
80
+ let result = renderConditionals(0).rendered;
81
+ const varRegex = /\{\{(\w+)\}\}/g;
82
+ result = result.replace(varRegex, (match, key) => {
83
+ const value = data[key];
84
+ return value !== undefined && value !== null ? String(value) : match;
85
+ });
86
+
87
+ return result;
88
+ }
89
+
17
90
  export async function handleTemplate(
18
91
  templatePath: string,
19
92
  data: Record<string, any> = {},
@@ -35,7 +108,7 @@ export async function handleTemplate(
35
108
  `${routerPrefix}${file
36
109
  .replace('.handlebars', fileExtra)
37
110
  .replace('npmrc', '.npmrc')}`.replace('language', 'ts')
38
- ] = `${renderString(fs.readFileSync(filePath, 'utf-8'), data)}`;
111
+ ] = renderTemplate(fs.readFileSync(filePath, 'utf-8'), data);
39
112
  } else {
40
113
  files[`${routerPrefix}${file}`] = `${fs.readFileSync(
41
114
  filePath,
@@ -56,12 +129,35 @@ async function handleCodesandboxTemplate() {
56
129
  return files;
57
130
  }
58
131
 
132
+ function resolvePackageRoot(entryPath: string, packageName: string): string {
133
+ let directory = path.dirname(entryPath);
134
+
135
+ while (directory !== path.dirname(directory)) {
136
+ const packageJsonPath = path.join(directory, 'package.json');
137
+ if (fs.existsSync(packageJsonPath)) {
138
+ const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
139
+ if (packageJson.name === packageName) {
140
+ return directory;
141
+ }
142
+ }
143
+ directory = path.dirname(directory);
144
+ }
145
+
146
+ throw new Error(`Unable to resolve package root for ${packageName}.`);
147
+ }
148
+
59
149
  async function handleCreateTemplate() {
60
150
  const createPackageMainPath = require.resolve('@modern-js/create');
61
- const createPackagePath = path.dirname(path.dirname(createPackageMainPath));
151
+ const createPackagePath = resolvePackageRoot(
152
+ createPackageMainPath,
153
+ '@modern-js/create',
154
+ );
62
155
  const createPackageJsonPath = path.join(createPackagePath, 'package.json');
63
156
 
64
- const templateDir = path.join(createPackagePath, 'template');
157
+ // Vendored copy of the upstream single-app MWA template (the old
158
+ // @modern-js/create `template/` directory). The workspace-shell template
159
+ // cannot run inside a browser Sandpack/Nodebox environment.
160
+ const templateDir = path.join(import.meta.dirname, 'mwa-template');
65
161
 
66
162
  const createPackageJson = JSON.parse(
67
163
  fs.readFileSync(createPackageJsonPath, 'utf-8'),