Skip to content

Commit

Permalink
fix: use host package name as a prefix for generated web sdk (#56)
Browse files Browse the repository at this point in the history
fix: use host package name as a prefix for generated web sdk
  • Loading branch information
roperzh committed Nov 14, 2019
1 parent 3618fbd commit 6eb06a6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion examples/playground/web/diez/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "diez",
"name": "playground-web-diez",
"version": "0.0.0",
"main": "index.js",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/targets/sources/web/sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "diez",
"name": "{{#with this.hostPackageName}}{{.}}-{{/with}}diez",
"version": "0.0.0",
"main": "index.js",
"license": "MIT",
Expand Down
14 changes: 14 additions & 0 deletions packages/targets/src/targets/web.handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,19 @@ const mergeDependency = (dependencies: Set<WebDependency>, newDependency: WebDep
dependencies.add(newDependency);
};

/**
* Tries to guess the name of the host package.
*
* @internal
*/
const guessHostPackageName = (destinationPath: string) => {
try {
return require(join(destinationPath, 'package.json')).name;
} catch (e) {
return '';
}
};

/**
* A compiler for web targets.
* @ignore
Expand Down Expand Up @@ -243,6 +256,7 @@ export class WebCompiler extends TargetCompiler<WebOutput, WebBinding> {
const tokens = {
devPort,
hostname,
hostPackageName: guessHostPackageName(this.program.destinationPath),
devMode: this.program.devMode,
dependencies: Array.from(this.output.dependencies),
sources: Array.from(this.output.sources).map((source) => readFileSync(source).toString()),
Expand Down

0 comments on commit 6eb06a6

Please sign in to comment.