Coder Social home page Coder Social logo

temp-write's Issues

Windows CI

Does this work on Windows? This does work on Windows. You're not using a Windows-based CI (AppVeyor) for anyone to see if tests pass.

Promisify the library

Remove the callback and add promises.

Will add a PR for this (which includes AVA for testing).

Path instead of fileName

I can't use this module because filename is not descriptive enough. For instance, this is perfect readable:

/var/folders/j3/5b59rnl11p98dhkyfv5b9nkr0000gn/T/1396396004094.2021/client/app/js/main.js:12: WARNING - app.ok is never defined
>>   return console.log(app.ok());

while this is no go:

/var/folders/j3/5b59rnl11p98dhkyfv5b9nkr0000gn/T/3a4238c7-cfb2-48a7-a413-194a7adcb962/59rnl11p98dhkyfv5b9n.js:11: ERROR - variable global is undeclared
  return global.React = require('react');

Which file failed? I don't know.

Cannot use import statement outside a module

Hello, I apologise for this question as it may be unrelated to your code and more because of my inexperience with JavaScript modules.

Recently I changed from temp-write 4.x to 5.x and encountered the following error:

Cannot use import statement outside a module

/Users/samuel/.atom/packages/script-runner/node_modules/temp-write/index.js:1
(function (exports, require, module, __filename, __dirname, process, global, Buffer) { return function (exports, require, module, __filename, __dirname) { import {promisify} from 'node:util';
                                                                                                                                                           ^^^^^^
SyntaxError: Cannot use import statement outside a module
    at new Script (vm.js:84:7)

It seems like maybe I'm using this incorrectly? But going back to 4.x the error goes away.

Support streams

Would you be open to allowing input to be a stream?

In an Electron app, I have a little save-url module that looks like this:

const fs = require('fs');
const path = require('path');
const got = require('got');
const tempfile = require('tempfile');

const saveUrl = (urlStr) => {
    const filePath = tempfile(path.extname(urlStr));

    return new Promise((resolve, reject) => {
        got.stream(urlStr)
            .pipe(fs.createWriteStream(filePath))
            .on('error', reject)
            .on('finish', () => {
                resolve(filePath);
            });
    });
};

I based this on some very similar code from you in wallpaper-cli.

Both of these would benefit if temp-write supported taking a stream as input.

In my case, my module would be reduced to:

const path = require('path');
const got = require('got');
const tempWrite = require('temp-write');

const saveUrl = (urlStr) => {
    return tempWrite(got.stream(urlStr), path.basename(urlStr));
};

Error ERR_REQUIRE_ESM

I get the following error:

Uncaught Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: C:\MyApp\node_modules\temp-write\index.js

I Use Latest NodeJS: 16.2.0
I Use Latest temp-write: 5.0.0

On macOS, os.tmpdir() isn't the real path

❯ node --version
v7.4.0
❯ node -pe 'os.tmpdir()'
/var/folders/_6/p8qxp_3n62zg9081tvb0lcc80000gn/T
❯ node -pe 'fs.realpathSync(os.tmpdir())'
/private/var/folders/_6/p8qxp_3n62zg9081tvb0lcc80000gn/T

When writing a Node.js module using temp-write, __filename inside that module is different than the file path that is returned by temp-write.

Using macOS Sierra 10.12.3.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.