Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
647 changes: 366 additions & 281 deletions Cargo.lock

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ env_logger = { version = "0.11.2", default-features = false }
log = { version = "0.4.19", features = ["std"] }

# Disable the watch and serve features, we only use mdbook as a library
mdbook = { version = "0.4.37", default-features = false, features = ["search"] }
mdbook = { version = "0.4.40", default-features = false, features = ["search"] }

# Disable unicode features, we don't need them
regex = { version = "1.9.1", default-features = false, features = [
"std",
"perf",
"std",
"perf",
] }

serde_json = "1.0.103"
Expand All @@ -35,8 +35,8 @@ serde = { version = "1.0.171", features = ["derive"] }
toml = "0.5.11"

# We use pulldown-cmark to mutate markdown, not to render HTML
pulldown-cmark = { version = "0.9.3", default-features = false }
pulldown-cmark-to-cmark = "11.2.0"
pulldown-cmark = { version = "0.10.0", default-features = false }
pulldown-cmark-to-cmark = "14.0.0"

pathdiff = "0.2.1"

Expand All @@ -45,9 +45,9 @@ anyhow = "1.0.71"
once_cell = "1.18.0"

swc_core = { version = "0.90.10", features = [
"common",
"ecma_parser_typescript",
"ecma_ast",
"common",
"ecma_parser_typescript",
"ecma_ast",
] }

chrono = { version = "0.4.26", default-features = false, features = ["clock"] }
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"build-scripts:playground": "esbuild --minify --format=esm --loader=js <src/js/playground-io.js >src/js/playground-io.min.js"
},
"devDependencies": {
"@angular/cli": "^17.0.0",
"@angular/cli": "^18.0.0",
"esbuild": "^0.18.12",
"express-check-in": "^0.1.2",
"husky": "8.0.3",
Expand Down
6 changes: 5 additions & 1 deletion src/angular/builder/background/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ fn open_pid_file(
.read(true)
.write(true)
.create(true)
.truncate(true)
.open(&pid_file_path)?;
}

Expand Down Expand Up @@ -149,7 +150,10 @@ pub(super) fn start(config: &Config) -> Result<()> {
// inside the fork!

unsafe {
let devnull_fd = libc::open((b"/dev/null\0" as *const [u8; 10]).cast(), libc::O_RDWR);
let devnull_fd = libc::open(
std::ptr::from_ref::<[u8; 10]>(b"/dev/null\0").cast(),
libc::O_RDWR,
);
if devnull_fd == -1 {
return Err(io::Error::last_os_error()).context("Failed to open /dev/null");
}
Expand Down
24 changes: 12 additions & 12 deletions src/codeblock/playground/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub(super) trait PlaygroundInputConfigExt {

fn as_boolean(&self) -> Option<bool>;
fn into_number(self) -> Option<serde_json::Number>;
fn into_string(self) -> Option<String>;
// fn into_string(self) -> Option<String>;

fn get_default(&self) -> Option<&Value>;
}
Expand Down Expand Up @@ -82,13 +82,13 @@ impl PlaygroundInputConfigExt for PlaygroundInputConfig {
}
}

fn into_string(self) -> Option<String> {
if let Some(Value::String(value)) = self.default_ {
Some(value)
} else {
None
}
}
// fn into_string(self) -> Option<String> {
// if let Some(Value::String(value)) = self.default_ {
// Some(value)
// } else {
// None
// }
// }

#[inline]
fn get_default(&self) -> Option<&Value> {
Expand Down Expand Up @@ -116,10 +116,10 @@ impl PlaygroundInputConfigExt for Option<PlaygroundInputConfig> {
self.and_then(PlaygroundInputConfigExt::into_number)
}

#[inline]
fn into_string(self) -> Option<String> {
self.and_then(PlaygroundInputConfigExt::into_string)
}
// #[inline]
// fn into_string(self) -> Option<String> {
// self.and_then(PlaygroundInputConfigExt::into_string)
// }

#[inline]
fn get_default(&self) -> Option<&Value> {
Expand Down
2 changes: 1 addition & 1 deletion src/js/experimental-builder/builder.min.mjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

118 changes: 72 additions & 46 deletions src/js/experimental-builder/builder.mjs
Original file line number Diff line number Diff line change
@@ -1,53 +1,79 @@
// If you change this file, run `yarn build-scripts`

import {buildApplicationInternal} from '@angular-devkit/build-angular/src/builders/application/index.js';
import {createBuilder} from '@angular-devkit/architect';
import fs from 'node:fs';
import {posix} from 'node:path';

export default createBuilder(
({optimization, watch = false, ...input}, context) => {
return buildApplicationInternal(
{
watch,
progress: false,

index: false,
entryPoints: new Set(
fs
.readdirSync(context.workspaceRoot)
.filter(file => {
let resolvedFile = posix.join(context.workspaceRoot, file);

return (
fs.statSync(resolvedFile).isDirectory() &&
fs.existsSync(`${resolvedFile}/${file}.ts`)
);
})
.map(file => `${file}/${file}.ts`),
),
aot: true,

tsConfig: 'tsconfig.json',
...input,

...(optimization
? {
optimization: {
styles: {
inlineCritical: false,
minify: true,
},
scripts: true,
},
outputHashing: 'all',
}
: {
optimization: false,
outputHashing: 'none',
}),
},
context,
/**
* @returns {Promise<import('@angular-devkit/build-angular/node_modules/@angular/build/src/builders/application/index.js')>}
*/
async function getBuildModule() {
try {
return await import(
// @ts-expect-error This file no longer exists in Angular 18
'@angular-devkit/build-angular/src/builders/application/index.js'
);
} catch {}

try {
// @ts-expect-error This file only exists if @angular/build is installed
return await import('@angular/build/src/builders/application/index.js');
} catch {}
try {
return await import(
'@angular-devkit/build-angular/node_modules/@angular/build/src/builders/application/index.js'
);
},
);
} catch {}

throw new Error(
'Unable to find builder function in @angular-devkit/build-angular or @angular/build',
);
}

export default createBuilder(async function* (
{optimization, watch = false, ...input},
context,
) {
yield* (await getBuildModule()).buildApplicationInternal(
{
watch,
progress: false,

index: false,
entryPoints: new Set(
fs
.readdirSync(context.workspaceRoot)
.filter(file => {
let resolvedFile = posix.join(context.workspaceRoot, file);

return (
fs.statSync(resolvedFile).isDirectory() &&
fs.existsSync(`${resolvedFile}/${file}.ts`)
);
})
.map(file => `${file}/${file}.ts`),
),
aot: true,

tsConfig: 'tsconfig.json',
...input,

...(optimization
? {
optimization: {
styles: {
inlineCritical: false,
minify: true,
},
scripts: true,
},
outputHashing: 'all',
}
: {
optimization: false,
outputHashing: 'none',
}),
},
context,
);
});
31 changes: 16 additions & 15 deletions src/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use handlebars::Handlebars;
use mdbook::book::Chapter;
use once_cell::sync::Lazy;
use pathdiff::diff_paths;
use pulldown_cmark::{CodeBlockKind, CowStr, Event, Parser, Tag};
use pulldown_cmark::{CodeBlockKind, CowStr, Event, Options, Parser, Tag, TagEnd};
use pulldown_cmark_to_cmark::cmark as markdown_to_string;
use regex::Regex;
use serde::Serialize;
Expand Down Expand Up @@ -122,8 +122,7 @@ struct CodeBlockCollector<'a, 'b> {

code_blocks: Vec<CodeBlock>,

in_codeblock: bool,
current_code: Option<String>,
current_code: Option<(String, Option<String>)>,

error: Result<()>,

Expand All @@ -150,7 +149,6 @@ impl<'a, 'c> CodeBlockCollector<'a, 'c> {
chapter,
code_blocks: Vec::new(),

in_codeblock: false,
current_code: None,

error: Ok(()),
Expand All @@ -171,29 +169,29 @@ impl<'a, 'c> CodeBlockCollector<'a, 'c> {

if let Event::Start(Tag::CodeBlock(CodeBlockKind::Fenced(language))) = &event {
if is_angular_codeblock(language) {
self.in_codeblock = true;
self.current_code = Some((language.as_ref().into(), None));
return ProcessedEvent::empty();
}
}

if self.in_codeblock {
if let Some((language, code)) = self.current_code.take() {
if let Event::Text(text) = &event {
self.current_code = Some(text.to_string());
self.current_code = Some((language, Some(text.to_string())));
return ProcessedEvent::empty();
}

if let Event::End(Tag::CodeBlock(CodeBlockKind::Fenced(language))) = &event {
self.in_codeblock = false;

let Some(code) = self.current_code.take() else {
if let Event::End(TagEnd::CodeBlock) = &event {
let Some(code) = code else {
return ProcessedEvent::multiple(vec![
Event::Start(Tag::CodeBlock(CodeBlockKind::Fenced(language.clone()))),
Event::End(Tag::CodeBlock(CodeBlockKind::Fenced(language.clone()))),
Event::Start(Tag::CodeBlock(CodeBlockKind::Fenced(language.into()))),
Event::End(TagEnd::CodeBlock),
]);
};

return self.insert_code_block(None, None, language, &code, &Some(&code));
}

self.current_code = Some((language, code));
}

let Event::Text(text) = &event else {
Expand Down Expand Up @@ -394,15 +392,18 @@ pub(crate) fn process_markdown(
config: &Config,
chapter: &mut Chapter,
) -> Result<Option<ChapterWithCodeBlocks>> {
let Some(source_path) = chapter.source_path.as_ref().map(Clone::clone) else {
let Some(source_path) = chapter.source_path.clone() else {
return Ok(None);
};

let mut new_content: String = String::with_capacity(chapter.content.len());
let mut collector = CodeBlockCollector::new(config, chapter)?;

let mut options = Options::all();
options.remove(Options::ENABLE_SMART_PUNCTUATION);

markdown_to_string(
Parser::new(&chapter.content).flat_map(|event| collector.process_event(event)),
Parser::new_ext(&chapter.content, options).flat_map(|event| collector.process_event(event)),
&mut new_content,
)
.context("Failed to serialize markdown")?;
Expand Down
16 changes: 8 additions & 8 deletions test-book/package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"devDependencies": {
"@angular-devkit/build-angular": "^17.0.0",
"@angular/cli": "^17.0.0",
"@angular/common": "^17.0.0",
"@angular/compiler": "^17.0.0",
"@angular/compiler-cli": "^17.0.0",
"@angular/core": "^17.0.0",
"@angular/platform-browser": "^17.0.0",
"@angular-devkit/build-angular": "^18.0.0",
"@angular/cli": "^18.0.0",
"@angular/common": "^18.0.0",
"@angular/compiler": "^18.0.0",
"@angular/compiler-cli": "^18.0.0",
"@angular/core": "^18.0.0",
"@angular/platform-browser": "^18.0.0",
"rxjs": "^7.8.1",
"typescript": "~5.2.2",
"typescript": "~5.4.0",
"zone.js": "^0.14.0"
}
}
Loading