Releases: suchipi/yavascript
0.0.12
Full Changelog: v0.0.11...v0.0.12
0.0.11
Full Changelog: v0.0.10...v0.0.11
0.0.10
Full Changelog: v0.0.9...v0.0.10
0.0.9
LOTS of new stuff in this release, though it's still far from complete
Full Changelog: v0.0.8...v0.0.9
v0.0.8
This release brings several exciting features, but the star of the show is definitely npm support!
Highlights
NPM support
You can now import packages directly from npm without needing to run npm install
by importing using the npm:
protocol:
import * as Preact from "npm:preact@^10.5.0";
Or, if you want to work with local npm packages in a node_modules
directory, you can install them as usual and then load them with either require
or import
:
$ npm install --save preact@^10.5.0
const Preact = require("preact");
Please be aware that although many npm packages will work, packages which use Node.js-specific builtins like fs
, path
, or vm
will not function unless you shim those builtin modules via Module.define
. I may include partial shims for common Node.js builtins like these in the future.
Import from http/https
You can now import modules from http/https URLs:
import * as Something from "https://something.example.com/something.js";
As always, please consult the typedefs by running yavascript --print-types
in order to see the documentation and type signatures of all APIs included in yavascript.
Details
Additions
- You can now import modules directly from http/https URLs. They will be fetched each time the script is evaluated. I will probably add caching options in the future.
import * as Something from "https://something.example.com/something.js";
- You can now import any npm package without installing it first, using the
npm:
prefix in an import URL. For example:This feature relies on Skypack, which converts CJS into ESM in the npm packages it serves.import * as Preact from "npm:preact@^10.5.0";
- npm packages will be fetched from the Skypack cdn each time your script is evaluated. I will probably add caching options in the future.
- You can now construct Path objects with template literals by using
Path.tag
and/orPath.tagUsingBase
- You can now pass
{ binary: true }
toreadFile
to get an ArrayBuffer instead of a string - There is now preliminary support for ESM <-> CJS interop
- If code appears to assign to
exports
ormodule.exports
(static code analysis heuristic), then the value ofmodule.exports
will be made available as a named export named__cjsExports
, and a named export named__isCjsModule
will be present which is a boolean indicating whethermodule.exports
orexports
were modified when the module was loaded. require
detects the above situation and returnsmodule.exports.__cjsExports
instead ofmodule.exports
, when appropriate.- Import statements and dynamic import do not handle
__cjsExports
specially. You may have to read off of__cjsExports
manually to get the values you want, when importing CommonJS files. Or you can userequire
to load them instead.
- If code appears to assign to
- The
node_modules
module lookup resolution algorithm is now partially supported.- The "exports" field of package.json is not yet supported. However, the "main" field is supported.
- If the package you want to import from only has an
exports
field, you can manually reach into the package to get the file it would export, ieimport * as something from "some-package/dist/index.mjs"
- A new
yavascript
global is available which can be used to detect whether code is running in yavascript. This global is an object which holds information about the running yavascript binary, including version, processor architecture, etc. - The transpilation functions yavascript uses when loading coffeescript/typescript/etc are now available as
yavascript.compilers
, eg. the functionyavascript.compilers.jsx
. - Several functions which accept string paths now also support Path objects in those places. Not all functions have support for this yet, though. Consult
yavascript --print-types
to understand which do and which don't.
Changes
- The
is
andassert
APIs have been changed significantly. Instead of various type-checking functions living as properties on bothis
andassert
, they are now on a newtypes
global, and should be passed to eitheris
(which is now a function instead of an object) orassert.type
(which is a new function). This is a breaking change.- This new
types
global also has functions for making compound types, like "and", "or", etc. It's based on pheno.
- This new
- The QuickJS builtin modules
std
andos
are now namespaced, and as such have been renamed toquickjs:std
andquickjs:os
. You should update your imports and requires accordingly. This is a breaking change. - Several APIs will now do runtime type checks on the values they receive to ensure that you're passing, for example, a string when you need to be passing a string. This allows us to have nicer error messages when an incorrect type is passed through.
Fixes
- When running files specified via relative paths at the CLI, is no longer necessary to prefix the paths with
./
or../
. An unprefixed path will search in the current working directory. - The Node.js-compatibility API
process.execPath
was mistakenly usingreadlink
on the result of the QuickJSos.execPath()
, when it should have been usingrealpath
. This has been fixed.
Caveats
http:
,https:
, andnpm:
imports rely oncurl
being available in your PATH. We (safely!) shell out tocurl
instead of including network fetching code in theyavascript
binary to keep it lean and also to ensure you can get security updates for OpenSSL and stuff without having to wait for a new version ofyavascript
. If you don't havecurl
installed on your system,http:
,https:
, andnpm:
imports will fail.- In order to support using
import
andrequire
interchangeably in any file without having to differentiate between scripts and modules, yavascript assumes all code is targeting the "module" goal. As such, strict mode is always on, and the toplevelthis
value is alwaysundefined
. This may cause some issues in some npm packages which expect to be run in non-strict mode. - Many npm packages depend on Node.js builtins like
fs
,path
,util
, orchild_process
. Those packages will not work in yavascript unless you shim those builtins by usingModule.define
. At some point in the future, I may add some small shims for the most common functionality of these builtins, but full Node.js compatibility is a non-goal. - The code to support Skypack relies on the fact that Skypack's sub-dependency files all have paths prefixed with
/-/
. The module loader will treat any path starting with/-/
as being from Skypack. This may cause problems in the unlikely event that you have a folder named-
in the root of your filesystem, because its contents will be "shadowed" by Skypack. I hope to remove this hack in the future by changing the module loader to be aware of the "current origin", like web browsers are.
Git Diff
v0.0.7
There's lots of new stuff in here! Merry Christmas!
Additions:
- added
cat
- yavascript's global APIs are now available as a separate library
- you can use it together with qjsbootstrap to make your own binaries
- added
require.resolve
(andstd.resolveModule
) - you can now require or import json
- added
printf
- added
os.execPath()
- attempting to use
mkdir
,cp
or other common commands which we have under a different name will now throw an error instructing you to useensureDir
,copy
, etc instead - the parser now supports multiple shebangs at the top of a file (for nix)
- Added
parseScriptArgs
(a command-line flag parser) - Added
startRepl
(start the repl from your own file, with your own globals) - We now support and provide binaries for linux arm
- Added
CSV.parse
,CSV.stringify
- Added
YAML.parse
,YAML.stringify
- Added
chmod
- Added
touch
- Added
assert
function, as well asassert.string(...)
,assert.object(...)
, etc, which throw TypeErrors with useful messages if their argument isn't correct - Added
grepString
,grepFile
, andString.prototype.grep
- Added
Module.define
(create your own builtin modules) - Added
String.cooked
andString.dedent
template tag helper functions - Added
setTimeout
,clearTimeout
,setInterval
andclearInterval
Changes:
- Added
Path
class (represents a filesystem path) and moved functions frompaths
namespace onto that class (both as instance and static methods) - language (js/jsx/ts/coffee) will now be autodetected for files with no extension. previously, it always assumed js
- you can now use
--lang
when running a file to specify the language for that file- it only affects the entrypoint file; all other imported/required files will have their lang determined by their extension or autodetect, as usual
cd()
(with no argument) now goes to your home dir- when compiling yavascript from source, the version will now include the git sha and whether the worktree was clean or not
- Help text now has colors (when stdout is a tty)
- APIs are now lazy-loaded; not loaded until they're first used. This reduces startup time
Fixes/Other:
- fixed a memory leak in
require
- Fixed lots of bugs with path string handling
- Improved the automated test suite (in the git repo)
- Other misc changes
Full Changelog: v0.0.6...v0.0.7
v0.0.6
- Add support for typescript, jsx, tsx, and coffeescript (autodetected based on file extension, or
--lang
flag when using the repl or--eval
) - Add
is
namespace which contains utility functions for checking the types of various values - Add
pipe
function (wip; converts some byte source (file, typedarray, string) into some other byte representation) - improve glob (also, its arguments changed, which is a breaking change)
- better inspection of FILE objects (from quickjs std/os modules)
- unify trace logging stuff (breaking:
exec.enableLogging
has been removed in favor of a newtrace
option) - add
clear
function (prints ansi control code to stdout) import
now works in the repl and in--eval
(by way of a simple ESM-to-CJS transform)- Add
--print-types
CLI flag to print out theyavascript.d.ts
that corresponds to a given binary, so the binary can be distributed on its own without losing the types - And some other misc changes
Full Changelog: v0.0.5...v0.0.6
0.0.5
small bugfix
- change some
export
keywords that were mistakenly makingyavascript.d.ts
a module intodeclare
instead (so that it remains a script, and therefore declares globals)
Full Changelog: v0.0.4...v0.0.5
v0.0.4
- better value inspector
- tons of bugfixes (mostly stuff related to paths, filesystems, symlinks, etc)
- most path-related stuff is now namespaced under
paths
global - lots of filesystem APIs added (
copy
,ensureDir
,isLink
, etc) - exec can accept a string now if you don't want to use an array
- but if you find yourself having to do weird stuff to escape spaces and quotes and etc, I suggest the array form
- glob search api added (
glob
function) - improved output format of thrown errors caught by the top-level script run
- most of the code has automated tests now
- we have an official docker image now: https://hub.docker.com/r/suchipi/yavascript
- it's
FROM scratch
with just the binary in it, and I'm very proud that that works :D
- it's
Full Changelog: v0.0.3...v0.0.4
0.0.3
Full Changelog: v0.0.2...v0.0.3
Highlights:
- Added --help, --version, --license, and --eval CLI options
- You no longer have to include the
.js
extension in import specifiers - Improvements to
env
- More options for
exec
- Change to default behavior for
$
: Now throws on nonzero exit code. Useexec
with options for the old behavior - Add
__filename
,__dirname
,makePath
,OS_PATH_SEPARATOR
- Add
realpath
,readlink
- Add
repoRoot
,isGitignored
repoRoot
works for either hg or git. I'm open to adding support for more version control systems; if you know a command-line invocation that will give the repo root, please let me know!
- We now build binaries for ARM macOS as well as the previously-existing amd64 macOS/Windows/Linux targets