Add .txt and .md text asset imports#190
Conversation
- Resolve `.txt` and `.md` through module imports - Expose `content` and frozen `metadata` exports - Update docs and tests for text asset loading
📝 WalkthroughWalkthroughExtended GocciaScript module system to support text-asset imports from Changes
Sequence DiagramsequenceDiagram
participant Client as Client Code
participant Resolver as TGocciaModuleResolver
participant Loader as TGocciaModuleLoader
participant ContentProvider as TGocciaContentProvider
participant Module as TGocciaModule
Client->>Resolver: Resolve "./note.txt" (or "./note")
Resolver->>Resolver: Probe ModuleImportExtensions<br/>(includes .txt, .md)
Resolver-->>Loader: Return resolved path
Loader->>Loader: Check IsTextAssetExtension()
Loader->>ContentProvider: LoadContent(ResolvedPath)
ContentProvider-->>Loader: Return UTF-8 string content
Loader->>Loader: Build frozen metadata<br/>(kind, path, fileName,<br/>extension, byteLength)
Loader->>Module: Create with exports:<br/>content, metadata
Module-->>Loader: Return TGocciaModule
Loader-->>Client: Return Module.Exports
Client->>Module: Access content & metadata
Module-->>Client: Return string & frozen object
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
tests/language/modules/text-import.js (1)
35-41: Namespace import test looks good, but key order assertion may be brittle.The assertion
expect(Object.keys(noteModule)).toEqual(["metadata", "content"])assumes a specific enumeration order. If the module loader's export table preserves insertion order (as ES modules do), this is fine. However, if the order changes in the future (e.g.,["content", "metadata"]), this test would fail even though the functionality is correct.Consider using a set-based comparison if order isn't semantically meaningful:
♻️ Optional: Order-agnostic assertion
- expect(Object.keys(noteModule)).toEqual(["metadata", "content"]); + expect(Object.keys(noteModule).sort()).toEqual(["content", "metadata"]);🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tests/language/modules/text-import.js` around lines 35 - 41, The test "supports namespace imports for text assets" is brittle because it asserts a specific key order with Object.keys(noteModule) === ["metadata","content"]; change this to an order-agnostic check on noteModule's keys (e.g., compare as a Set, or use arrayContaining plus a length check) so the test verifies both keys exist and no extras without relying on enumeration order; update the assertion that references noteModule accordingly.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@tests/language/modules/text-import.js`:
- Around line 35-41: The test "supports namespace imports for text assets" is
brittle because it asserts a specific key order with Object.keys(noteModule) ===
["metadata","content"]; change this to an order-agnostic check on noteModule's
keys (e.g., compare as a Set, or use arrayContaining plus a length check) so the
test verifies both keys exist and no extras without relying on enumeration
order; update the assertion that references noteModule accordingly.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 93b99373-eb82-463b-9def-f6a9329dbe46
📒 Files selected for processing (14)
AGENTS.mdREADME.mddocs/code-style.mddocs/design-decisions.mddocs/embedding.mddocs/language-restrictions.mdtests/language/modules/helpers/guide.mdtests/language/modules/helpers/note.txttests/language/modules/text-import.jsunits/Goccia.Constants.PropertyNames.pasunits/Goccia.FileExtensions.pasunits/Goccia.Modules.ContentProvider.Test.pasunits/Goccia.Modules.Loader.pasunits/Goccia.Modules.Resolver.pas
Benchmark Results274 benchmarks Interpreted: 🟢 223 improved · 🔴 13 regressed · 38 unchanged · avg +5.5% arraybuffer.js — Interp: 🟢 12, 🔴 1, 1 unch. · avg +7.7% · Bytecode: 🟢 12, 🔴 2 · avg +7.6%
arrays.js — Interp: 🟢 19 · avg +9.3% · Bytecode: 🟢 15, 🔴 3, 1 unch. · avg +5.7%
async-await.js — Interp: 🟢 6 · avg +11.2% · Bytecode: 🟢 6 · avg +12.5%
classes.js — Interp: 🟢 23, 8 unch. · avg +6.1% · Bytecode: 🟢 11, 🔴 5, 15 unch. · avg +2.4%
closures.js — Interp: 🟢 11 · avg +7.5% · Bytecode: 🟢 5, 6 unch. · avg +1.6%
collections.js — Interp: 🟢 9, 🔴 3 · avg +3.5% · Bytecode: 🟢 10, 2 unch. · avg +3.6%
destructuring.js — Interp: 🟢 19, 3 unch. · avg +5.1% · Bytecode: 🟢 7, 🔴 1, 14 unch. · avg +1.7%
fibonacci.js — Interp: 🟢 8 · avg +6.8% · Bytecode: 🟢 6, 2 unch. · avg +5.9%
for-of.js — Interp: 🟢 5, 2 unch. · avg +3.4% · Bytecode: 🟢 5, 🔴 1, 1 unch. · avg +2.5%
helpers/bench-module.js — Interp: 0 · Bytecode: 0
iterators.js — Interp: 🟢 16, 4 unch. · avg +3.1% · Bytecode: 🟢 10, 🔴 4, 6 unch. · avg +1.6%
json.js — Interp: 🟢 15, 5 unch. · avg +7.3% · Bytecode: 🟢 16, 🔴 1, 3 unch. · avg +7.8%
jsx.jsx — Interp: 🟢 13, 8 unch. · avg +2.5% · Bytecode: 🟢 7, 🔴 7, 7 unch. · avg +0.4%
modules.js — Interp: 🟢 8, 1 unch. · avg +5.3% · Bytecode: 🟢 6, 3 unch. · avg +1.9%
numbers.js — Interp: 🟢 11 · avg +9.6% · Bytecode: 🟢 10, 1 unch. · avg +9.7%
objects.js — Interp: 🟢 4, 🔴 1, 2 unch. · avg +2.4% · Bytecode: 🔴 1, 6 unch. · avg -1.5%
promises.js — Interp: 🟢 8, 🔴 1, 3 unch. · avg +2.8% · Bytecode: 🟢 10, 2 unch. · avg +3.4%
regexp.js — Interp: 🟢 11 · avg +5.3% · Bytecode: 🟢 4, 🔴 4, 3 unch. · avg +0.4%
strings.js — Interp: 🟢 11 · avg +7.7% · Bytecode: 🟢 6, 🔴 1, 4 unch. · avg +1.5%
typed-arrays.js — Interp: 🟢 14, 🔴 7, 1 unch. · avg +1.8% · Bytecode: 🟢 9, 🔴 9, 4 unch. · avg +0.6%
Measured on ubuntu-latest x64. Benchmark ranges compare cached main-branch min/max ops/sec with the PR run; overlapping ranges are treated as unchanged noise. Percentage deltas are secondary context. |
Suite Timing
Measured on ubuntu-latest x64. |
- Canonicalize CRLF and bare CR in `.txt`/`.md` module content - Add regression coverage for imported text assets - Update docs to describe the normalized `content` export
Summary
.txtand.mdextensions.contentfor raw UTF-8 text andmetadatafor frozen file metadata.Testing
units/Goccia.Modules.ContentProvider.Test.pasfor loading UTF-8.txtmodules.tests/language/modules/text-import.jsfor content, metadata, extensionless resolution, and namespace imports.tests/language/modules/helpers/for.txtand.mdasset imports.Summary by CodeRabbit
Release Notes
New Features
.txtand.mdfiles as modules with named exports for filecontentandmetadata(including file path, name, extension, and byte length)./noteresolves to./note.txt)Documentation