Skip to content

Commit 3bc0f1a

Browse files
authored
Fix build-examples script on windows (#21591)
* Fix build-examples script on windows * Fix LGTM warning
1 parent d9a5084 commit 3bc0f1a

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

utils/build/rollup.examples.config.js

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import babel from '@rollup/plugin-babel';
22
import path from 'path';
3+
import os from 'os';
34
import glob from 'glob';
45
import babelrc from './.babelrc.json';
56

7+
const EOL = os.EOL;
8+
69
function babelCleanup() {
710

811
const doubleSpaces = / {2}/g;
@@ -21,7 +24,7 @@ function babelCleanup() {
2124
// {
2225
// ↓
2326
// setSize: function () {
24-
code = code.replace( /\(\)\n\s*\/\*([a-zA-Z0-9_, ]+)\*\/\n\s*{/g, '( ) {' );
27+
code = code.replace( new RegExp( `\\(\\)${EOL}\\s*\\/\\*([a-zA-Z0-9_, ]+)\\*\\/${EOL}\\s*{`, 'g' ), '( ) {' );
2528

2629

2730
return {
@@ -52,14 +55,14 @@ function unmodularize() {
5255
code = code.replace( /export { ([a-zA-Z0-9_, ]+) };/g, ( match, p1 ) => {
5356

5457
const exps = p1.split( ', ' );
55-
return exps.map( exp => `THREE.${exp} = ${exp};` ).join( '\n' );
58+
return exps.map( exp => `THREE.${exp} = ${exp};` ).join( EOL );
5659

5760
} );
5861

5962
// import { Example } from '...';
6063
// but excluding imports importing from the libs/ folder
6164
const imports = [];
62-
code = code.replace( /import { ([a-zA-Z0-9_, ]+) } from '((?!libs).)*';\n/g, ( match, p1 ) => {
65+
code = code.replace( /import { ([a-zA-Z0-9_, ]+) } from '((?!libs).)*';/g, ( match, p1 ) => {
6366

6467
const imps = p1.split( ', ' );
6568
imps.reverse();
@@ -100,30 +103,30 @@ function unmodularize() {
100103
// fix for BasisTextureLoader.js
101104
imports.forEach( imp => {
102105

103-
code = code.replace( new RegExp( `\n(\\s)THREE\.${imp}:`, 'g' ), ( match, p1 ) => {
106+
code = code.replace( new RegExp( `${EOL}(\\s)THREE\\.${imp}:`, 'g' ), ( match, p1 ) => {
104107

105-
return `\n${p1}${imp}:`;
108+
return `${EOL}${p1}${imp}:`;
106109

107110
} );
108111

109112
} );
110113

111114
// import * as THREE from '...';
112-
code = code.replace( /import \* as THREE from '(.*)';\n/g, '' );
115+
code = code.replace( /import \* as THREE from '(.*)';/g, '' );
113116

114117
// Remove library imports that are exposed as
115118
// global variables in the non-module world
116-
code = code.replace( 'import * as fflate from \'../libs/fflate.module.min.js\';\n', '' );
117-
code = code.replace( 'import { MMDParser } from \'../libs/mmdparser.module.js\';\n', '' );
118-
code = code.replace( 'import { potpack } from \'../libs/potpack.module.js\';\n', '' );
119-
code = code.replace( 'import { opentype } from \'../libs/opentype.module.min.js\';\n', '' );
120-
code = code.replace( 'import { chevrotain } from \'../libs/chevrotain.module.min.js\';\n', '' );
121-
code = code.replace( 'import { ZSTDDecoder } from \'../libs/zstddec.module.js\';\n', '' );
119+
code = code.replace( 'import * as fflate from \'../libs/fflate.module.min.js\';', '' );
120+
code = code.replace( 'import { MMDParser } from \'../libs/mmdparser.module.js\';', '' );
121+
code = code.replace( 'import { potpack } from \'../libs/potpack.module.js\';', '' );
122+
code = code.replace( 'import { opentype } from \'../libs/opentype.module.min.js\';', '' );
123+
code = code.replace( 'import { chevrotain } from \'../libs/chevrotain.module.min.js\';', '' );
124+
code = code.replace( 'import { ZSTDDecoder } from \'../libs/zstddec.module.js\';', '' );
122125

123126
// remove newline at the start of file
124127
code = code.trimStart();
125128

126-
code = `( function () {\n${code}\n} )();`;
129+
code = `( function () {${EOL}${code}${EOL}} )();`;
127130

128131
return {
129132
code: code,

0 commit comments

Comments
 (0)