-
-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7800 from keymanapp/change/web/util-modularization
change(web): util package modularization, bundling 🧩
- Loading branch information
Showing
17 changed files
with
1,332 additions
and
650 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Bundles @keymanapp/web-utils as single-file modules based upon the export list in src/index.ts. | ||
*/ | ||
|
||
import esbuild from 'esbuild'; | ||
import { spawn } from 'child_process'; | ||
|
||
// Bundles to a compact ESModule | ||
esbuild.buildSync({ | ||
entryPoints: ['build/version.inc.js'], | ||
bundle: true, | ||
sourcemap: true, | ||
//minify: true, // No need to minify a module. | ||
//keepNames: true, | ||
format: "cjs", | ||
// Sets 'common/web' as a root folder for module resolution; | ||
// this allows the keyman-version import to resolve. | ||
nodePaths: ['..'], | ||
outfile: "build/index.cjs", | ||
tsconfig: 'tsconfig.json', | ||
target: "es5" | ||
}); | ||
|
||
const dtsBundleCommand = spawn('npx dts-bundle-generator --project tsconfig.json -o build/index.d.ts version.inc.ts', { | ||
shell: true | ||
}); | ||
|
||
dtsBundleCommand.stdout.on('data', data => console.log(data.toString())); | ||
dtsBundleCommand.stderr.on('data', data => console.error(data.toString())); | ||
|
||
// Forces synchronicity; done mostly so that the logs don't get jumbled up. | ||
dtsBundleCommand.on('exit', () => { | ||
if(dtsBundleCommand.exitCode != 0) { // Ensure the exit code gets emitted! | ||
process.exit(dtsBundleCommand.exitCode); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Bundles @keymanapp/web-utils as single-file modules based upon the export list in src/index.ts. | ||
*/ | ||
|
||
import esbuild from 'esbuild'; | ||
import { spawn } from 'child_process'; | ||
|
||
// Bundles to a compact ESModule | ||
esbuild.buildSync({ | ||
entryPoints: ['build/obj/index.js'], | ||
bundle: true, | ||
sourcemap: true, | ||
//minify: true, // No need to minify a module. | ||
//keepNames: true, | ||
format: "esm", | ||
// Sets 'common/web' as a root folder for module resolution; | ||
// this allows the keyman-version import to resolve. | ||
nodePaths: ['..'], | ||
outfile: "build/lib/index.mjs", | ||
tsconfig: 'tsconfig.json', | ||
target: "es5" | ||
}); | ||
|
||
// Bundles to a compact CommonJS (classic Node) module | ||
esbuild.buildSync({ | ||
entryPoints: ['build/obj/index.js'], | ||
bundle: true, | ||
sourcemap: true, | ||
//minify: true, // No need to minify a module. | ||
//keepNames: true, | ||
format: "cjs", | ||
// Sets 'common/web' as a root folder for module resolution; | ||
// this allows the keyman-version import to resolve. | ||
nodePaths: ['..'], | ||
outfile: "build/lib/index.cjs", | ||
tsconfig: 'tsconfig.json', | ||
target: "es5" | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,23 @@ | ||
namespace com.keyman.utils { | ||
/** | ||
* Function deepCopy | ||
* Scope Private | ||
* @param {Object} p object to copy | ||
* @param {Array=} c0 array member being copied | ||
* @return {Object} clone ('deep copy') of object | ||
* Description Makes an actual copy (not a reference) of an object, copying simple members, | ||
* arrays and member objects but not functions, so use with care! | ||
*/ | ||
export function deepCopy<T>(p:T, c0?): T { | ||
var c = c0 || {}; | ||
for (var i in p) { | ||
if(typeof p[i] === 'object' && p[i] != null) { | ||
c[i] = (p[i].constructor === Array ) ? [] : {}; | ||
deepCopy(p[i],c[i]); | ||
} | ||
else { | ||
c[i] = p[i]; | ||
} | ||
/** | ||
* Function deepCopy | ||
* Scope Private | ||
* @param {Object} p object to copy | ||
* @param {Array=} c0 array member being copied | ||
* @return {Object} clone ('deep copy') of object | ||
* Description Makes an actual copy (not a reference) of an object, copying simple members, | ||
* arrays and member objects but not functions, so use with care! | ||
*/ | ||
export default function deepCopy<T>(p:T, c0?): T { | ||
var c = c0 || {}; | ||
for (var i in p) { | ||
if(typeof p[i] === 'object' && p[i] != null) { | ||
c[i] = (p[i].constructor === Array ) ? [] : {}; | ||
deepCopy(p[i],c[i]); | ||
} | ||
else { | ||
c[i] = p[i]; | ||
} | ||
|
||
return c; | ||
} | ||
|
||
return c; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.