sinclairzx81 / typescript-bundle

A Bundling Tool for TypeScript
MIT License
126 stars 6 forks source link

define function is missing #18

Closed NicoVogel closed 4 years ago

NicoVogel commented 4 years ago

I have an interesting problem where the define function is not added, but it only happens in my WSL2 Ubuntu 18.04.

SETUP

git clone https://github.com/nicovogel/docker-extension test
cd test
npm install
npm run build #the postbuild will fail in CMD and PS, because its a shell script
head -n 20 dist/docker-extension.js

My result when using PS

(() => {
    const defines = {};
    const entry = [null];
    function define(name, dependencies, factory) {
        defines[name] = { dependencies, factory };
        entry[0] = name;
    }
    define("require", ["exports"], (exports) => {
        Object.defineProperty(exports, "__cjsModule", { value: true });
        Object.defineProperty(exports, "default", { value: (name) => resolve(name) });
    });
    #!/usr/bin/env node
    define("defaultConfig", ["require", "exports"], function (require, exports) {
        "use strict";
        Object.defineProperty(exports, "__esModule", { value: true });
        exports.defaultConfig = {
            showCommand: true,
            default: 'c',
            commandMappings: {
                c: {

My result when using WSL2 Ubuntu 18.04

#!/usr/bin/env node

define("defaultConfig", ["require", "exports"], function (require, exports) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    exports.defaultConfig = {
        showCommand: true,
        default: 'c',
        commandMappings: {
            c: {
                command: 'container',
                default: 'ps',
                actionMappings: [
                    ['p', 'prune'],
                    ['e', 'exec'],
                    ['i', 'inspect']
                ]
            },
            i: {
                command: 'image',

System information

Ubuntu: lsb_release -a

No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 18.04.4 LTS
Release:        18.04
Codename:       bionic

Windows: winver

Version 2004 (OS Build 19041.264)

More information

I asked a few people to check this, but only I encounter the issue (non of them could check WSL2, only WSL1).

I have tried:

I don't know if the issue has anything to do with this repo, but its definitely strange. Do you have some form of verbose logging I can enable to dig deeper?

sinclairzx81 commented 4 years ago

Hi.

At first glance i would has a guess it has something to do with the timing around WSL file system watch events. As TypeScript-Bundle is driven purely from the TSC CLI (and due to there not being any mechanism in the TSC CLI to signal when content has been written to disk), TypeScript-Bundle runs a file system watcher on the target output file --outFile and when it sees the file has changed, it reads the content and rewrites it back with a AMD loader (that includes the define). If there is issues around these events, or latent events, it may skip over rewriting the content.

The relevant code for this can be found here, However im unable to test and reproduce WSL errors as I am currently don't have access to a Windows machine.

The issue you describe does seem like its watch event related however. TypeScript-Bundle seems to take the same code path when using --watch and one off compilation. It might be possible to provide a direct code path for one off compilation that doesn't implicate file system watchers at all.

Hope this helps

NicoVogel commented 4 years ago

Hi, Thank you for the quick response. This could be the issue and I will be looking into it a little more at some point. But for now, my workaround is to use Webpack, which requires more configuration than your tool.