Skip to content

Astroctx v1.1.0

Choose a tag to compare

@shuritch shuritch released this 01 Oct 18:01
· 68 commits to main since this release

2023-10-01

Major updates

  • Removed astro syntax with type option, now only supports common js syntax.
  • Context updates
    1. Renamed to sandbox, example: Astroctx.sandbox
    2. To create new contexts you should use Astroctx.sandbox({ myCtxVariable: 'test' })
    3. All presets still should be working properly with Astroctx.sandbox[preset-key]
  • Reader updates
    1. Joined with require, now require works as reader, examples:
      Astroctx.require('./my-path/to/script.js');
      Astroctx.require.script('./my-path/to/script.js');
      Astroctx.require.dir('./my-path/to');
    2. New access controll feature, see access updates
  • Access updates, now this option work for both sandbox and reader, you need to provide function
    const option = { access: pathOrModule => pathOrModule === 'fs' || pathOrModule.endsWith('.js') };
    Astroctx.execute('module.exports = require("fs")');
    Astroctx.read('./path/to/script.js');
    // But you still can controll them by each own function
    const option = {
      access: {
        internal: path => true, // Reader controll
        sandbox: module => {}, // Sandbox require controll
      },
    };

    Sandbox function can return object or boolean value, in case of object it will be used as stub
    content

Minor updates

  • Created new tests, new tests coverage ~85%

  • NPM Isolation fix, now it should work properly

    const script = Astroctx.execute(`module.exports = require('chalk')`, {
      access: { sandbox: () => true },
      npmIsolation: true,
      ctx: sandbox.NODE,
    }); // Output: Chalk function