Node library (created in TS): Correct way to export avoiding duplicates - ready for publishing?












2















Can anyone help?



I just created a node library that I want to publish to npm - currently, I am testing it locally.



I have 2 directories that present models, these 2 directories have unique files but there are a few files where the name is the same i.e. meta-data.ts, requirements.ts - These files are automatically generated and although now these 2 files are the same across the 2 directories - they could diverge in the future.



My libraries are compiled to js and placed in a /dist directory and then in the root i am doing



export * "./models/red"
export * "./models/blue"


but this isn't possible as there are files the same.



the structure of the package that would be published would be



 
index.js
dist
models
red
..files
blue
..files


Now I can't really import them from the subdirectories on publishing because that means that in production I would have to import ( not in the same place)



  import {MetaData} packagename/dist/models/red

import {MetaData} packagename/dist/models/blue


Hence I would need to include the dist folder in there and while developing locally this dist does not exist - and also the dist is the compiled files.



Also including the dist on the import just doesn't seem right



So I am wondering if I am doing this correctly and what my options are?



I thought I had to EXPORT all files from the root that I want my package to expose?



Also, there is no syntax for "exporting "as"



I don't want to rename my models, they should co-exist.



Of course, if I was importing the files locally without going through a package then I would not have this problem as i could import them relatively from the models



  import {MetaData} ./models/red

import {MetaData} ./models/blue









share|improve this question



























    2















    Can anyone help?



    I just created a node library that I want to publish to npm - currently, I am testing it locally.



    I have 2 directories that present models, these 2 directories have unique files but there are a few files where the name is the same i.e. meta-data.ts, requirements.ts - These files are automatically generated and although now these 2 files are the same across the 2 directories - they could diverge in the future.



    My libraries are compiled to js and placed in a /dist directory and then in the root i am doing



    export * "./models/red"
    export * "./models/blue"


    but this isn't possible as there are files the same.



    the structure of the package that would be published would be



     
    index.js
    dist
    models
    red
    ..files
    blue
    ..files


    Now I can't really import them from the subdirectories on publishing because that means that in production I would have to import ( not in the same place)



      import {MetaData} packagename/dist/models/red

    import {MetaData} packagename/dist/models/blue


    Hence I would need to include the dist folder in there and while developing locally this dist does not exist - and also the dist is the compiled files.



    Also including the dist on the import just doesn't seem right



    So I am wondering if I am doing this correctly and what my options are?



    I thought I had to EXPORT all files from the root that I want my package to expose?



    Also, there is no syntax for "exporting "as"



    I don't want to rename my models, they should co-exist.



    Of course, if I was importing the files locally without going through a package then I would not have this problem as i could import them relatively from the models



      import {MetaData} ./models/red

    import {MetaData} ./models/blue









    share|improve this question

























      2












      2








      2








      Can anyone help?



      I just created a node library that I want to publish to npm - currently, I am testing it locally.



      I have 2 directories that present models, these 2 directories have unique files but there are a few files where the name is the same i.e. meta-data.ts, requirements.ts - These files are automatically generated and although now these 2 files are the same across the 2 directories - they could diverge in the future.



      My libraries are compiled to js and placed in a /dist directory and then in the root i am doing



      export * "./models/red"
      export * "./models/blue"


      but this isn't possible as there are files the same.



      the structure of the package that would be published would be



       
      index.js
      dist
      models
      red
      ..files
      blue
      ..files


      Now I can't really import them from the subdirectories on publishing because that means that in production I would have to import ( not in the same place)



        import {MetaData} packagename/dist/models/red

      import {MetaData} packagename/dist/models/blue


      Hence I would need to include the dist folder in there and while developing locally this dist does not exist - and also the dist is the compiled files.



      Also including the dist on the import just doesn't seem right



      So I am wondering if I am doing this correctly and what my options are?



      I thought I had to EXPORT all files from the root that I want my package to expose?



      Also, there is no syntax for "exporting "as"



      I don't want to rename my models, they should co-exist.



      Of course, if I was importing the files locally without going through a package then I would not have this problem as i could import them relatively from the models



        import {MetaData} ./models/red

      import {MetaData} ./models/blue









      share|improve this question














      Can anyone help?



      I just created a node library that I want to publish to npm - currently, I am testing it locally.



      I have 2 directories that present models, these 2 directories have unique files but there are a few files where the name is the same i.e. meta-data.ts, requirements.ts - These files are automatically generated and although now these 2 files are the same across the 2 directories - they could diverge in the future.



      My libraries are compiled to js and placed in a /dist directory and then in the root i am doing



      export * "./models/red"
      export * "./models/blue"


      but this isn't possible as there are files the same.



      the structure of the package that would be published would be



       
      index.js
      dist
      models
      red
      ..files
      blue
      ..files


      Now I can't really import them from the subdirectories on publishing because that means that in production I would have to import ( not in the same place)



        import {MetaData} packagename/dist/models/red

      import {MetaData} packagename/dist/models/blue


      Hence I would need to include the dist folder in there and while developing locally this dist does not exist - and also the dist is the compiled files.



      Also including the dist on the import just doesn't seem right



      So I am wondering if I am doing this correctly and what my options are?



      I thought I had to EXPORT all files from the root that I want my package to expose?



      Also, there is no syntax for "exporting "as"



      I don't want to rename my models, they should co-exist.



      Of course, if I was importing the files locally without going through a package then I would not have this problem as i could import them relatively from the models



        import {MetaData} ./models/red

      import {MetaData} ./models/blue






      node.js typescript npm






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jan 2 at 7:44









      Mark SmithMark Smith

      2314




      2314
























          0






          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54002849%2fnode-library-created-in-ts-correct-way-to-export-avoiding-duplicates-ready%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54002849%2fnode-library-created-in-ts-correct-way-to-export-avoiding-duplicates-ready%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          MongoDB - Not Authorized To Execute Command

          in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith

          Npm cannot find a required file even through it is in the searched directory