Skip to content

Commit

Permalink
Merge pull request #695 from smapiot/develop
Browse files Browse the repository at this point in the history
Release 1.5.6
  • Loading branch information
FlorianRappl committed May 21, 2024
2 parents 4751e2b + aa8dcfe commit 62c8455
Show file tree
Hide file tree
Showing 12 changed files with 122 additions and 21 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
# Piral Changelog

## 1.5.6 (tbd)

- Fixed issue with `piral-cli-webpack5` when modifying the config entry point
- Fixed issue with pre-TypeScript 5 versions with module resolution set to `bundler`
- Fixed handling of max event listeners for `pilet debug`
- Updated to latest version of `dets`
- Added dynamic compiler capability to `piral-ng`

## 1.5.5 (May 10, 2024)

- Fixed `piral-ng/extend-webpack` for MJS files using not fully specified references
- Updated TypeScript to use module resolution set to `bundler`
- Added `piral-ng/standalone` to support pure modern Angular standalone (#690)

## 1.5.4 (April 23, 2024)
Expand Down
2 changes: 1 addition & 1 deletion docs/specs/cli-specification.md
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ Critical is the correct definition of the `externals` and the output formatting.
This specification was created by [smapiot](https://smapiot.com).
The initial author was [Florian Rappl](https://twitter.com/FlorianRappl). The review was done by [Lothar Schöttner](https://smapiot.com). Suggestions from [Jens Thirmeyer](https://www.iotcloudarchitect.com) have been taken into consideration.
The initial author was [Florian Rappl](https://twitter.com/FlorianRappl). The review was done by [Lothar Schöttner](https://smapiot.com). Suggestions from [Jens Thirmeyer](https://linkedin.com/in/jens-thirmeyer) have been taken into consideration.
## References
Expand Down
2 changes: 1 addition & 1 deletion docs/specs/feed-api-specification.md
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ We recommend using a model that distinguishes between **features** and **pilets*

This specification was created by [smapiot](https://smapiot.com).

The initial author was [Florian Rappl](https://twitter.com/FlorianRappl). The review was done by [Lothar Schöttner](https://smapiot.com). Suggestions from [Jens Thirmeyer](https://www.iotcloudarchitect.com) have been taken into consideration.
The initial author was [Florian Rappl](https://twitter.com/FlorianRappl). The review was done by [Lothar Schöttner](https://smapiot.com). Suggestions from [Jens Thirmeyer](https://linkedin.com/in/jens-thirmeyer) have been taken into consideration.

## References

Expand Down
2 changes: 1 addition & 1 deletion docs/specs/pilet-specification.md
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ The maximum specified file size of a pilet is 16 MB. Anything larger is potentia

This specification was created by [smapiot](https://smapiot.com).

The initial author was [Florian Rappl](https://twitter.com/FlorianRappl). The review was done by [Lothar Schöttner](https://smapiot.com). Suggestions from [Jens Thirmeyer](https://www.iotcloudarchitect.com) have been taken into consideration.
The initial author was [Florian Rappl](https://twitter.com/FlorianRappl). The review was done by [Lothar Schöttner](https://smapiot.com). Suggestions from [Jens Thirmeyer](https://de.linkedin.com/in/jens-thirmeyer) have been taken into consideration.

## References

Expand Down
2 changes: 1 addition & 1 deletion mlc_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@
"pattern": "^https://azure.microsoft.com/"
}
],
"aliveStatusCodes": [429, 200]
"aliveStatusCodes": [401, 403, 429, 200]
}
70 changes: 70 additions & 0 deletions src/converters/piral-ng/compiler-dynamic.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import info from '@angular/compiler/package.json';

if (typeof window.ngVersions === 'undefined') {
window.ngVersions = {};
}

const defaultVersion = 'default';
const existing = Object.getOwnPropertyDescriptor(window, 'ng');

function setUrl(url, version) {
if (version) {
window.ngVersions[url] = version;
return version;
}

return defaultVersion;
}

setUrl(new URL('.', __system_context__.meta.url).href, info.version);

if (existing?.get === undefined) {
const ngs = {
[defaultVersion]: existing?.value,
};

function getUrl() {
const { stack } = new Error();
const lines = stack?.split('\n') || [];

if (lines[0] === 'Error') {
// V8
const line = lines[3] || '';
return /\((.*):\d+:\d+\)$/.exec(line)?.[1] || '';
} else {
// SpiderMonkey and JavaScriptCore
const line = lines[2] || '';
return /@(.*):\d+:\d+$/.exec(line)?.[1] || '';
}
}

function getNgVersion(url) {
const version = window.ngVersions[url];

if (!version) {
try {
const baseUrl = new URL('.', url);
const baseVersion = window.ngVersions[baseUrl.href];
return setUrl(url, baseVersion);
} catch {
return defaultVersion;
}
}

return version;
}

Object.defineProperty(window, 'ng', {
configurable: true,
get() {
const url = getUrl();
const version = getNgVersion(url);
return ngs[version];
},
set(value) {
const url = getUrl();
const version = getNgVersion(url);
ngs[version] = value;
},
});
}
26 changes: 19 additions & 7 deletions src/converters/piral-ng/extend-webpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,18 +101,30 @@ module.exports =
);

if (jitMode) {
// The job of this plugin is to make angular-core depend on angular-compiler - this way
// angular-compiler does not need to be loaded separately and angular-compiler is present
// *before* angular-core
// this is only required in jit mode - as otherwise everything should be pre-compiled
// The job of this plugin is
// (1)
// to make @angular/core depend on @angular/compiler - this way @angular/compiler
// does not need to be loaded separately and @angular/compiler is present *before*
// @angular/core; this is only required in jit mode - as otherwise everything should
// be pre-compiled.
// (2)
// to introduce a dynamic version of the window.ng global, which supports running
// with multiple versions of Angular.
config.plugins.push({
apply(compiler) {
const { entry } = compiler.options;
const core = entry['angular-core'];
const coreEntry = entry['angular-core'];

if (typeof core !== 'undefined') {
if (typeof coreEntry !== 'undefined') {
const compilerDependency = resolve(__dirname, 'core-dynamic.js');
core.import = [compilerDependency, ...core.import];
coreEntry.import = [compilerDependency, ...coreEntry.import];
}

const compilerEntry = entry['angular-compiler'];

if (typeof compilerEntry !== 'undefined') {
const compilerDependency = resolve(__dirname, 'compiler-dynamic.js');
compilerEntry.import = [compilerDependency, ...compilerEntry.import];
}
},
});
Expand Down
4 changes: 4 additions & 0 deletions src/converters/piral-ng/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
"./common": {
"import": "./common.js"
},
"./compiler-dynamic": {
"import": "./compiler-dynamic.js"
},
"./convert": {
"import": "./convert.js"
},
Expand Down Expand Up @@ -58,6 +61,7 @@
"src",
"common.d.ts",
"common.js",
"compiler-dynamic.js",
"convert.d.ts",
"convert.js",
"core-dynamic.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ export function extractParts(content: cheerio.Root) {
}

export function getTemplates(entry: Entry): Array<string> {
if (typeof entry === 'string' && entry.endsWith('.html')) {
return [entry];
if (typeof entry === 'string') {
return getTemplates([entry]);
} else if (Array.isArray(entry)) {
return entry.filter((e) => e.endsWith('.html'));
} else if (typeof entry !== 'function') {
Expand Down
2 changes: 1 addition & 1 deletion src/tooling/piral-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
},
"dependencies": {
"css-conflict-inspector": "^0.2.1",
"dets": "^0.14.2",
"dets": "^0.15.1",
"kras": "^0.16.1",
"rimraf": "^3.0.0",
"typescript": "^5.0.0",
Expand Down
11 changes: 6 additions & 5 deletions src/tooling/piral-cli/src/apps/debug-pilet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,12 @@ export async function debugPilet(baseDir = process.cwd(), options: DebugPiletOpt
if (allEntries.length === 0) {
fail('entryFileMissing_0077');
}

const maxListeners = Math.max(2 + allEntries.length * 2, 16);

process.stderr?.setMaxListeners(maxListeners);
process.stdout?.setMaxListeners(maxListeners);
process.stdin?.setMaxListeners(maxListeners);

const buildRef = await watcherTask(async (watcherContext) => {
const pilets = await concurrentWorkers(allEntries, concurrency, async (entryModule) => {
Expand Down Expand Up @@ -329,11 +335,6 @@ export async function debugPilet(baseDir = process.cwd(), options: DebugPiletOpt

const watcherRef = await watcherTask(async (watcherContext) => {
const { pilets } = buildRef.data;
const maxListeners = Math.max(2 + allEntries.length * 2, 16);

process.stderr?.setMaxListeners(maxListeners);
process.stdout?.setMaxListeners(maxListeners);
process.stdin?.setMaxListeners(maxListeners);

await hooks.beforeApp?.({ appInstanceDir, pilets });

Expand Down
9 changes: 7 additions & 2 deletions src/tooling/piral-cli/src/common/io.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import rimraf from 'rimraf';
import { transpileModule, ModuleKind, ModuleResolutionKind, ScriptTarget, JsxEmit } from 'typescript';
import { transpileModule, ModuleKind, ModuleResolutionKind, ScriptTarget, JsxEmit, version } from 'typescript';
import { join, resolve, basename, dirname, extname } from 'path';
import { exists, lstat, unlink, statSync } from 'fs';
import { mkdtemp, mkdir, constants } from 'fs';
Expand Down Expand Up @@ -492,6 +492,11 @@ export async function move(source: string, target: string, forceOverwrite = Forc
return source;
}

function isVersion5OrHigher() {
const currentMajor = parseInt(version.split('.').shift());
return currentMajor >= 5;
}

export async function getSourceFiles(entry: string) {
const dir = dirname(entry);
log('generalDebug_0003', `Trying to get source files from "${dir}" ...`);
Expand Down Expand Up @@ -519,7 +524,7 @@ export async function getSourceFiles(entry: string) {
checkJs: false,
jsx: JsxEmit.React,
module: ModuleKind.ESNext,
moduleResolution: ModuleResolutionKind.Bundler,
moduleResolution: isVersion5OrHigher() ? ModuleResolutionKind.Bundler : ModuleResolutionKind.Node10,
target: ScriptTarget.ESNext,
},
}).outputText;
Expand Down

0 comments on commit 62c8455

Please sign in to comment.