Skip to content

Commit

Permalink
fix(export): export client runtime from @stencil/core
Browse files Browse the repository at this point in the history
- Export esm client runtime
- Export cjs mocked client runtime only for node unit testing
- Refactor internal/stencil-core files
  • Loading branch information
adamdbradley committed Aug 15, 2020
1 parent 61e56da commit 4c6cb60
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 22 deletions.
10 changes: 6 additions & 4 deletions package.json
Expand Up @@ -2,8 +2,9 @@
"name": "@stencil/core",
"version": "2.0.0-2",
"license": "MIT",
"main": "internal/stencil-core/index.js",
"types": "internal/stencil-core/index.d.ts",
"main": "./internal/stencil-core/index.cjs",
"module": "./internal/stencil-core/index.js",
"types": "./internal/stencil-core/index.d.ts",
"bin": {
"stencil": "bin/stencil"
},
Expand Down Expand Up @@ -137,5 +138,6 @@
"custom elements",
"pwa",
"progressive web app"
]
}
],
"dependencies": {}
}
21 changes: 7 additions & 14 deletions scripts/bundles/internal.ts
@@ -1,5 +1,5 @@
import fs from 'fs-extra';
import { BuildOptions } from '../utils/options';
import type { BuildOptions } from '../utils/options';
import { cleanDts } from '../utils/bundle-dts';
import { internalAppData } from './interal-app-data';
import { internalClient } from './internal-platform-client';
Expand All @@ -15,7 +15,7 @@ export async function internal(opts: BuildOptions) {

await copyStencilInternalDts(opts, opts.output.internalDir);

await createStencilCoreEntry(opts.output.internalDir);
await copyStencilCoreEntry(opts);

// copy @stencil/core/internal default entry, which defaults to client
// but we're not exposing all of Stencil's internal code (only the types)
Expand Down Expand Up @@ -72,14 +72,6 @@ async function copyStencilInternalDts(opts: BuildOptions, outputInternalDir: str
const runtimeDts = cleanDts(await fs.readFile(runtimeDtsSrcPath, 'utf8'));
await fs.writeFile(runtimeDtsDestPath, runtimeDts);

// @stencil/core/internal/stencil-core/index.d.ts file
// actual public dts when importing @stencil/core
const stencilCoreDtsSrc = join(opts.buildDir, 'declarations', 'stencil-core', 'index.d.ts');
const stencilCoreDstDir = join(outputInternalDir, 'stencil-core');
const stencilCoreDtsDst = join(stencilCoreDstDir, 'index.d.ts');
await fs.ensureDir(stencilCoreDstDir);
await fs.copyFile(stencilCoreDtsSrc, stencilCoreDtsDst);

// @stencil/core/internal/stencil-ext-modules.d.ts (.svg/.css)
const srcExtModuleOutput = join(opts.srcDir, 'declarations', 'stencil-ext-modules.d.ts');
const dstExtModuleOutput = join(outputInternalDir, 'stencil-ext-modules.d.ts');
Expand All @@ -90,9 +82,10 @@ function prependExtModules(content: string) {
return `/// <reference path="./stencil-ext-modules.d.ts" />\n` + content;
}

async function createStencilCoreEntry(outputInternalDir: string) {
// write @stencil/core entry (really only used for node resolving, not its actual code as you can see)
const stencilCoreDstDir = join(outputInternalDir, 'stencil-core');
async function copyStencilCoreEntry(opts: BuildOptions) {
// write @stencil/core entry
const stencilCoreSrcDir = join(opts.srcDir, 'internal', 'stencil-core');
const stencilCoreDstDir = join(opts.output.internalDir, 'stencil-core');
await fs.ensureDir(stencilCoreDstDir);
await fs.writeFile(join(stencilCoreDstDir, 'index.js'), `exports.h = function() {};`);
await fs.copy(stencilCoreSrcDir, stencilCoreDstDir);
}
1 change: 1 addition & 0 deletions src/internal/stencil-core/index.cjs
@@ -0,0 +1 @@
exports.h = function () {};
Expand Up @@ -10,11 +10,11 @@ export type {
EventOptions,
FunctionalComponent,
FunctionalUtilities,
JSX,
MethodOptions,
ModeStyles,
ListenOptions,
ListenTargetOptions,
JSX,
PropOptions,
QueueApi,
RafCallback,
Expand All @@ -34,12 +34,12 @@ export {
forceUpdate,
h,
Host,
Method,
Listen,
Method,
Prop,
readTask,
setMode,
setAssetPath,
setMode,
State,
Watch,
writeTask,
Expand Down
14 changes: 14 additions & 0 deletions src/internal/stencil-core/index.js
@@ -0,0 +1,14 @@
export {
Build,
getAssetPath,
getElement,
getMode,
getRenderingRef,
forceUpdate,
h,
Host,
readTask,
setMode,
setAssetPath,
writeTask,
} from '../client/index.js';
1 change: 0 additions & 1 deletion tsconfig.json
Expand Up @@ -54,7 +54,6 @@
"src/compiler/index.ts",
"src/compiler/public.ts",
"src/compiler/sys/modules/index.ts",
"src/declarations/stencil-core/index.ts",
"src/dev-server/index.ts",
"src/dev-server/public.ts",
"src/dev-server/server-worker.ts",
Expand Down

0 comments on commit 4c6cb60

Please sign in to comment.