How to use the @magento/upward-js.IOAdapter function in @magento/upward-js

To help you get started, we’ve selected a few @magento/upward-js examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Jordaneisenburger / fallback-studio / src / pwa-studio / packages / pwa-buildpack / lib / WebpackTools / plugins / UpwardDevServerPlugin.js View on Github external
async createMiddleware() {
        // The compiler is necessary to build the fallback filesystem
        // so UPWARd can use Webpack-generated assets in dev mode.
        const compiler = await this.getCompiler();

        // Standard filesystem-and-fetch IO.
        const defaultIO = upward.IOAdapter.default(this.upwardPath);

        // Use Webpack's in-memory file system for UPWARD file retrieval during
        // development. Allows for hot reloading of server-side configuration.

        const io = {
            async readFile(filepath, enc = 'utf8') {
                // If a version of the file is output by Webpack into the output folder, prefer that one.
                const outputBasedPath = path.resolve(
                    compiler.options.output.path,
                    path.relative(compiler.options.context, filepath)
                );
                // Most likely scenario: UPWARD needs an output asset.
                debug(
                    'compiler.outputFileSystem readFile %s %s',
                    outputBasedPath,
                    enc
github Jordaneisenburger / fallback-studio / src / pwa-studio / packages / pwa-buildpack / lib / WebpackTools / plugins / __tests__ / UpwardDevServerPlugin.spec.js View on Github external
upward.middleware.mockResolvedValueOnce(upwardHandler);

    const noRequestsWaiting = new UpwardDevServerPlugin({}, process.env);
    noRequestsWaiting.apply(compiler);
    expect(noRequestsWaiting.compiler).toBe(compiler);

    const hasRequestsWaiting = new UpwardDevServerPlugin(
        devServer,
        process.env,
        'path/to/upward'
    );
    devServer.after(app);
    const handler = app.use.mock.calls[0][0];

    handler(req, res, next);
    expect(upward.IOAdapter.default).not.toHaveBeenCalled();
    expect(upward.middleware).not.toHaveBeenCalled();
    expect(hasRequestsWaiting.middlewarePromise).toBeInstanceOf(Promise);

    hasRequestsWaiting.apply(compiler);
    await hasRequestsWaiting.middlewarePromise;

    expect(upward.IOAdapter.default).toHaveBeenCalledWith('path/to/upward');
    expect(upward.middleware).toHaveBeenCalledWith(
        'path/to/upward',
        process.env,
        expect.objectContaining({
            readFile: expect.any(Function),
            networkFetch: expect.any(Function)
        })
    );
    expect(upwardHandler).toHaveBeenCalledWith(req, res, next);
github Jordaneisenburger / fallback-studio / src / pwa-studio / packages / pwa-buildpack / lib / WebpackTools / plugins / __tests__ / UpwardDevServerPlugin.spec.js View on Github external
devServer,
        process.env,
        'path/to/upward'
    );
    devServer.after(app);
    const handler = app.use.mock.calls[0][0];

    handler(req, res, next);
    expect(upward.IOAdapter.default).not.toHaveBeenCalled();
    expect(upward.middleware).not.toHaveBeenCalled();
    expect(hasRequestsWaiting.middlewarePromise).toBeInstanceOf(Promise);

    hasRequestsWaiting.apply(compiler);
    await hasRequestsWaiting.middlewarePromise;

    expect(upward.IOAdapter.default).toHaveBeenCalledWith('path/to/upward');
    expect(upward.middleware).toHaveBeenCalledWith(
        'path/to/upward',
        process.env,
        expect.objectContaining({
            readFile: expect.any(Function),
            networkFetch: expect.any(Function)
        })
    );
    expect(upwardHandler).toHaveBeenCalledWith(req, res, next);
});

@magento/upward-js

Implementation of the UPWARD spec as a NodeJS server

OSL-3.0
Latest version published 2 years ago

Package Health Score

67 / 100
Full package analysis